2019牛客ACM暑期多校第三场

B-Crazy Binary String (前缀和 +记录下标 On)

 

题目描述

ZYB loves binary strings (strings that only contains `0' and `1'). And he loves equal binary strings\textit{equal binary strings}equal binary strings more, where the number of `0' and the number of `1' in the string are equal.

ZYB wants to choose a substring from an original string  T\ T T so that it is an equal binary string\textit{equal binary string}equal binary string with the longest length possible. He also wants to choose a subsequence of  T\ T T which meets the same requirements.

A string  v\ v v is a substring of a string  w\ w w if  v\ v v is empty, or there are two integers  l\ l l and r (1≤l≤r≤∣w∣)r \ (1 \le l \le r \le |w|)r (1≤l≤r≤∣w∣) such that v=wlwl+1⋯wrv=w_lw_{l+1}\cdots w_rv=wl​wl+1​⋯wr​. A string  v\ v v is a subsequence of a string  w\ w w  if it can be derived from  w\ w w  by deleting any number (including zero) of characters without changing the order of the remaining characters. 

For simplicity, you only need to output the maximum possible length. Note that the empty string is both a substring and a subsequence of any string.

输入描述:

The first line of the input contains a single integer N (1≤N≤100000)N \ (1 \le N \leq 100000)N (1≤N≤100000), the length of the original string  T\ T T. The second line contains a binary string with exactly  N\ N N characters, the original string  T\ T T.

输出描述:

Print two integers  A\ A A and  B\ B B, denoting the answer for substring and subsequence respectively.

示例1

输入

复制

8
01001001

输出

复制

4 6

1.求连续的最长序列使0 1个数相等  2.求非连续的最长序列 使0 1个数相等

第二问并不难求,min(0的个数,1的个数)*2即可。

第一问不难想到前缀和,前缀和相同的两项索引相减 即子串长度,求最值。

n^2会T!n^2会T!n^2会T!

正解:On;扫一遍,记录每个前缀和数据对应的最小下标,不断更新ans。

注意:如果遇到字符0前缀和要减1的话,前缀和会出现负值,所以要把记录下标的数组开2倍大小,从中间操作。

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
const int inf=0x3f3f3f3f;
int pre[2*N];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        memset(pre,inf,sizeof(pre));
        int tmp=N;
        pre[N]=0;
        int ans=0;
        int cnt=0;
        char c;
        getchar();
        for(int i=1;i<=n;i++)
        {
            c=getchar();
            if(c=='1')
            {
                tmp++;
                cnt++;
            }
            else
                tmp--;
            pre[tmp]=min(i,pre[tmp]);
            ans=max(i-pre[tmp],ans);
//            cout<<ans<<'\n';
        }
        cout<<ans<<' '<<min(cnt,n-cnt)*2<<'\n';
    }
    return 0;
}

 

E-Magic Line (几何水题)

 

题目描述

There are always some problems that seem simple but is difficult to solve.

ZYB got  N\ N N distinct points on a two-dimensional plane. He wants to draw a magic line so that the points will be divided into two parts, and the number of points in each part is the same. There is also a restriction: this line can not pass through any of the points.

Help him draw this magic line.

输入描述:

There are multiple cases. The first line of the input contains a single integer T (1≤T≤10000)T \ (1 \leq T \leq 10000)T (1≤T≤10000), indicating the number of cases. 

For each case, the first line of the input contains a single even integer N (2≤N≤1000)N \ (2 \leq N \leq 1000)N (2≤N≤1000), the number of points. The following $N$ lines each contains two integers xi,yi (∣xi,yi∣≤1000)x_i, y_i  \ (|x_i, y_i| \leq 1000)xi​,yi​ (∣xi​,yi​∣≤1000), denoting the x-coordinate and the y-coordinate of the  i\ i i-th point.

It is guaranteed that the sum of  N\ N N over all cases does not exceed 2×1052 \times 10^52×105.

输出描述:

For each case, print four integers x1,y1,x2,y2x_1, y_1, x_2, y_2x1​,y1​,x2​,y2​ in a line, representing a line passing through (x1,y1)(x_1, y_1)(x1​,y1​) and (x2,y2)(x_2, y_2)(x2​,y2​). Obviously the output must satisfy (x1,y1)≠(x2,y2)(x_1,y_1) \ne (x_2,y_2)(x1​,y1​)​=(x2​,y2​).

The absolute value of each coordinate must not exceed 10910^9109. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.

示例1

输入

复制

1
4
0 1
-1 0
1 0
0 -1

输出

复制

-1 999000000 1 -999000001

仔细想想会发现这是一道水题

给一堆整点,求一条直线把这对点均分且这条直线不能压点。

由于可以随机输出任意一对点,还是整数,关键是这个题的x y还有范围!给你的一堆点的横纵坐标都在-1000~1000以内 

首先对点进行排序,x从小到大排,x相同时y从小到大排。然后让我们来看一下中间的两个点,假设一共n个点。

1.排序后第n/2个点和第n/2+1个点的横坐标如果不同的话 也就是说这些点可以按x坐标均分,并且中间两个点的横坐标至少差1(

因为都是整数),这时取第n/2个点的横坐标作为x1值和一个很大的数作为y1值(超出1000即可),取第n/2+1个点的横坐标作为x2值和-y1作为y2,得到两个点,输出就行。

2.如果中间两个点的横坐标相同,即这堆点不能按x坐标均分时,比较两点的纵坐标,如果相差大于1,可以直接选取第n/2个点的上面那个点和一个如同1中的点。如果相差小于1,取二者中间那个非整数点,分别向上加和向下减个相同的非整数(比如10000.5),得到两个纵坐标。

#include <bits/stdc++.h>
using namespace std;
struct point
{
    int x,y;
}s[1050];
bool cmp(point a,point b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    else if(a.x==b.x&&a.y!=b.y)
        return a.y<b.y;
}
int main()
{
    int t,n,m;
    scanf("%d",&t);
    while(t--)
    {
        memset(s,0,sizeof(s));
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d%d",&s[i].x,&s[i].y);
        sort(s+1,s+n+1,cmp);
        if(s[n/2].x!=s[n/2+1].x)
            cout<<s[n/2].x<<' '<<10000<<' '<<s[n/2+1].x<<' '<<-10000<<'\n';
        else
        {
            if(s[n/2+1].y-s[n/2].y>1)
                cout<<s[n/2].x-1<<' '<<10000<<' '<<s[n/2].x<<' '<<s[n/2].y+1<<'\n';
            else
                cout<<s[n/2].x-1<<' '<<s[n/2].y+10000<<' '<<s[n/2].x+1<<' '<<s[n/2].y-9999<<'\n';
        }
    }
    return 0;
}

 

F-Planting Trees 

 

题目描述

The semester is finally over and the summer holiday is coming. However, as part of your university's graduation requirement, you have to take part in some social service during the holiday. Eventually, you decided to join a volunteer group which will plant trees in a mountain.

 

To simplify the problem, let's represent the mountain where trees are to be planted with an N×NN \times NN×N grid. Let's number the rows 1\ 1 1 to N\ N N from top to bottom, and number the columns 1\ 1 1 to N\ N N from left to right. The elevation of the cell in the i\ i i-th row and j\ j j-th column is denoted by ai,ja_{i,j}ai,j​. Your leader decides that trees should be planted in a rectangular area within the mountain and that the maximum difference in elevation among the cells in that rectangle should not exceed M. In other words, if the coordinates of the top-left and the bottom-right corners of the rectangle are (x1,y1)(x_1,y_1)(x1​,y1​) and (x2,y2)(x_2,y_2)(x2​,y2​), then the condition ∣ai,j−ak,l∣≤M|a_{i,j} - a_{k,l}| \le M∣ai,j​−ak,l​∣≤M must hold for x1≤i,k≤x2, y1≤j,l≤y2x_1 \le i,k \le x_2, \ y_1 \le j,l \le y_2x1​≤i,k≤x2​, y1​≤j,l≤y2​. Please help your leader calculate the maximum possible number of cells in such a rectangle so that he'll know how many trees will be planted.

输入描述:

The input contains multiple cases. The first line of the input contains a single integer T (1≤T≤1000)T \ (1 \le T \le 1000)T (1≤T≤1000), the number of cases.
For each case, the first line of the input contains two integers N (1≤N≤500)N\ (1 \le N \le 500)N (1≤N≤500) and M (0≤M≤105)M\ (0 \le M \le 10^5)M (0≤M≤105). The following N lines each contain N integers, where the j\ j j-th integer in the i\ i i-th line denotes ai,j (1≤ai,j≤105)a_{i,j} \ (1 \le a_{i,j} \le 10^5)ai,j​ (1≤ai,j​≤105).
It is guaranteed that the sum of N3N^3N3 over all cases does not exceed 25⋅10725 \cdot 10^725⋅107.

输出描述:

For each case, print a single integer, the maximum number of cells in a valid rectangle.

示例1

输入

复制

2
2 0
1 2
2 1
3 1
1 3 2
2 3 1
3 2 1

输出

复制

1
4

待补。

全部评论

相关推荐

避坑恶心到我了大家好,今天我想跟大家聊聊我在成都千子成智能科技有限公司(以下简称千子成)的求职经历,希望能给大家一些参考。千子成的母公司是“同创主悦”,主要经营各种产品,比如菜刀、POS机、电话卡等等。听起来是不是有点像地推销售公司?没错,就是那种类型的公司。我当时刚毕业,急需一份临时工作,所以在BOSS上看到了千子成的招聘信息。他们承诺无责底薪5000元,还包住宿,这吸引了我。面试的时候,HR也说了同样的话,感觉挺靠谱的。于是,我满怀期待地等待结果。结果出来后,我通过了面试,第二天就收到了试岗通知。试岗的内容就是地推销售,公司划定一个区域,然后你就得见人就问,问店铺、问路人,一直问到他们有意向为止。如果他们有兴趣,你就得摇同事帮忙推动,促进成交。说说一天的工作安排吧。工作时间是从早上8:30到晚上18:30。早上7点有人叫你起床,收拾后去公司,然后唱歌跳舞(销售公司都这样),7:55早课(类似宣誓),8:05同事间联系销售话术,8:15分享销售技巧,8:30经理训话。9:20左右从公司下市场,公交、地铁、自行车自费。到了市场大概10点左右,开始地推工作。中午吃饭时间大约是12:00,公司附近的路边盖饭面馆店自费AA,吃饭时间大约40分钟左右。吃完饭后继续地推工作,没有所谓的固定中午午休时间。下午6点下班后返回公司,不能直接下班,需要与同事交流话术,经理讲话洗脑。正常情况下9点下班。整个上班的一天中,早上到公司就是站着的,到晚上下班前都是站着。每天步数2万步以上。公司员工没有自己的工位,百来号人挤在一个20平方米的空间里听经理洗脑。白天就在市场上奔波,公司的投入成本几乎只有租金和工资,没有中央空调。早上2小时,晚上加班2小时,纯蒸桑拿。没有任何福利,节假日也没有3倍工资之类的。偶尔会有冲的酸梅汤和西瓜什么的。公司的晋升路径也很有意思:新人—组长—领队—主管—副经理—经理。要求是业绩和团队人数,类似传销模式,把人留下来。新人不能加微信、不能吐槽公司、不能有负面情绪、不能谈恋爱、不能说累。在公司没有任何坐的地方,不能依墙而坐。早上吃早饭在公司外面的安全通道,未到上班时间还会让你吃快些不能磨蹭。总之就是想榨干你。复试的时候,带你的师傅会给你营造一个钱多事少离家近的工作氛围,吹嘘工资有多高、还能吹自己毕业于好大学。然后让你早点来公司、无偿加班、抓住你可能不会走的心思进一步压榨你。总之,大家在找工作的时候一定要擦亮眼睛,避免踩坑!———来自网友
qq乃乃好喝到咩噗茶:不要做没有专业门槛的工作
点赞 评论 收藏
分享
06-20 21:22
已编辑
门头沟学院 Java
纯真的河老师在喝茶:答应了就跑啊,实习随便跑啊,别被pua了,md就是找个廉价劳动力,还平稳过度正式工,到时候跟你说没转正
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务