Educational Codeforces Round 43 (Rated for Div. 2) ABCDE

A. Minimum Binary Number
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".

You are given a correct string s.

You can perform two different operations on this string:

  1. swap any pair of adjacent characters (for example, "101"  "110");
  2. replace "11" with "1" (for example, "110"  "10").

Let val(s) be such a number that s is its binary representation.

Correct string a is less than some other correct string b iff val(a) < val(b).

Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).

Input

The first line contains integer number n (1 ≤ n ≤ 100) — the length of string s.

The second line contains the string s consisting of characters "0" and "1". It is guaranteed that the string s is correct.

Output

Print one string — the minimum correct string that you can obtain from the given one.

Examples
input
Copy
4
1001
output
Copy
100
input
Copy
1
1
output
Copy
1
Note

In the first example you can obtain the answer by the following sequence of operations: "1001"  "1010"  "1100"  "100".

In the second example you can't obtain smaller answer no matter what operations you use.

 


 

题意:对一一个数的二进制表示可以进行两个操作:交换相邻两个二进制位以及合并两个1为一个1,问通过这两个操作能得到的不含前导0的最小数字是多少。
 
题解:特判0输出0,否则输出一个1,以及k个0,k是原01串里0的个数。
 1 #include
 2 #define clr(x) memset(x,0,sizeof(x))
 3 #define mod 1000000007
 4 #define clr_1(x) memset(x,-1,sizeof(x))
 5 #define INF 0x3f3f3f3f
 6 #define LL long long
 7 #define pb push_back
 8 #define pbk pop_back
 9 using namespace std;
10 const int N=1e5+10;
11 char s[N];
12 int n,m,zero,one;
13 int main()
14 {
15     scanf("%d",&n);
16     scanf("%s",s);
17     for(int i=0;s[i];i++)
18     {
19         if(s[i]=='0')
20             zero++;
21         else
22             one++;
23     }
24     if(n==1 && zero==1)
25     {
26         printf("0\n");
27         return 0;
28     }
29     else
30     {
31         printf("1");
32         while(zero)
33         {
34             printf("0");
35             zero--;
36         }
37         printf("\n");
38     }
39     return 0;
40 }
View Code

 

B. Lara Croft and the New Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.

Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.

Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. nand m given are such that she always end up in cell (1, 2).

Lara has already moved to a neighbouring cell k times. Can you determine her current position?

Input

The only line contains three integers nm and k (2 ≤ n, m ≤ 109, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!

Output

Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.

Examples
input
Copy
4 3 0
output
Copy
1 1
input
Copy
4 3 11
output
Copy
1 2
input
Copy
4 3 7
output
Copy
3 2


题意:有一个人在n*m的方格里走,每次只能走通往上下左右的一步。不过他有既定路线:先从(1,1)到(n,1),然后蛇形地走,每次从(k,2)走(k,m)然后到(k-1,m)接着到(k-1,2)然后到(k-2,2)这样不断循环。然后问你他走第k步的时候在哪里。

 

题解:先处理(1,1)到(1,n)的情况,然后通过取模整除处理余下情况。

 1 #include
 2 #define clr(x) memset(x,0,sizeof(x))
 3 #define mod 1000000007
 4 #define clr_1(x) memset(x,-1,sizeof(x))
 5 #define INF 0x3f3f3f3f
 6 #define LL long long
 7 #define pb push_back
 8 #define pbk pop_back
 9 using namespace std;
10 const int N=1e5+10;
11 LL n,m,k,s,row,col,t;
12 int main()
13 {
14     scanf("%I64d%I64d%I64d",&n,&m,&k);
15     if(k<n)
16     {
17         printf("%I64d 1\n",k+1);
18         return 0;
19     }
20     k-=n-1;
21     m--;
22     s=k%m;
23     t=k/m;
24     if(s==0)
25     {
26         row=n-t+1;
27         col=(t&1)?m+1:2;
28     }
29     else
30     {
31         row=n-t;
32         col=(t&1)?m+2-s:1+s;
33     }
34     printf("%I64d %I64d\n",row,col);
35     return 0;
36 }
View Code

 

C. Nested Segments
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices iand j such that segment ai lies within segment aj.

Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.

Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.

Input

The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.

Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.

Output

Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.

Examples
input
Copy
5
1 10
2 9
3 9
2 3
2 9
output
Copy
2 1
input
Copy
3
1 5
2 6
6 20
output
Copy
-1 -1


 

题意:给你一堆一维的线段的左右端点,让你找出一条线段完全被包含在另一条线段的情况,并输出这两条线段编号。若没有输出-1 -1。

 

题解:经典黑书线段覆盖题,按左端点为第一关键字从小到大,右端点为第二关键字从大到小排序就好了。

 1 #include
 2 #define clr(x) memset(x,0,sizeof(x))
 3 #define mod 1000000007
 4 #define clr_1(x) memset(x,-1,sizeof(x))
 5 #define INF 0x3f3f3f3f
 6 #define LL long long
 7 #define pb push_back
 8 #define pbk pop_back
 9 using namespace std;
10 const int N=3e5+10;
11 struct sem
12 {
13     int l,r,id;
14 }seg[N];
15 bool cmp(sem a,sem b)
16 {
17     if(a.l==b.l) return a.r>b.r;
18     return a.l<b.l;
19 }
20 int u,v,n,maxr,id;
21 int main()
22 {
23     scanf("%d",&n);
24     for(int i=1;i<=n;i++)
25     {
26         scanf("%d%d",&seg[i].l,&seg[i].r);
27         seg[i].id=i;
28     }
29     sort(seg+1,seg+n+1,cmp);
30     for(int i=2;i<=n;i++)
31     {
32         if(seg[i].l==seg[i-1].l)
33         {
34             printf("%d %d\n",seg[i].id,seg[i-1].id);
35             return 0;
36         }
37         else if(seg[i].r<=seg[i-1].r)
38         {
39             printf("%d %d\n",seg[i].id,seg[i-1].id);
40             return 0;
41         }
42     }
43     printf("-1 -1\n");
44     return 0;
45 }
View Code

 

 

D. Degree Set
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a sequence of n positive integers d1, d2, ..., dn (d1 < d2 < ... < dn). Your task is to construct an undirected graph such that:

  • there are exactly dn + 1 vertices;
  • there are no self-loops;
  • there are no multiple edges;
  • there are no more than 106 edges;
  • its degree set is equal to d.

Vertices should be numbered 1 through (dn + 1).

Degree sequence is an array a with length equal to the number of vertices in a graph such that ai is the number of vertices adjacent toi-th vertex.

Degree set is a sorted in increasing order sequence of all distinct values from the degree sequence.

It is guaranteed that there exists such a graph that all the conditions hold, and it contains no more than 106 edges.

Print the resulting graph.

Input

The first line contains one integer n (1 ≤ n ≤ 300) — the size of the degree set.

The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 1000, d1 < d2 < ... < dn) — the degree set.

Output

In the first line print one integer m (1 ≤ m ≤ 106) — the number of edges in the resulting graph. It is guaranteed that there exists such a graph that all the conditions hold and it contains no more than 106 edges.

Each of the next m lines should contain two integers vi and ui (1 ≤ vi, ui ≤ dn + 1) — the description of the i-th edge.

Examples
input
Copy
3
2 3 4
output
Copy
8
3 1
4 2
4 5
2 5
5 1
3 2
2 1
5 3
input
Copy
3
1 2 3
output
Copy
4
1 2
1 3
1 4
2 3

 

题意:给出无向图所有节点的度组成的集合(集合默认从大到小并且不重复),且无向图中无重边自环,节点数为最高度+1。询问一种构造方式能构造出一个符合上述度集以及要求的图,输出所有的边。保证一定有这样的图存在。
 
题解:保证存在那就直接莽,别慌。设总节点数为$ d_n +1 $。设我们从度集左右两边以及按照编号大小两边同时构造这个图。首先r为当前和其他点连边的结点点,l为r所可以连接到的编号最低的结点,即每次我们都将r与[l,r-1]连边。那么我们的r结点连完以后有$ d_n+2-l $的度(r右侧的结点都是有跟r连边的)。按编号两边构造的意思是我们每次构造出指定要求的度数点后l要增加,r要减少。设rt为度集最右侧的还未出现过的度数下标$ d_{rt} $即为该度数,lt为度集最左侧的还未出现过的度数下标$ d_{lt} $即为该度数。那我们每次构造就要构造出一对$ d_{rt} 和 d_{lt} $ 然后lt++,rt--。
    对$ d_{lt} $构造,那么我们需要$d_n+1 $到 $ d_n+1-d_{lt} $ 号r侧的点实行上述的连边操作,那么l的结点的度就会达到要求的$ d_{lt} $。那么假如现在 l 的度数为 $ degree_l $ ,那么我们只需要 $ [ r- d_{lt} - degree_l+1,r] $ 这些点实行上述的连边操作,那么$ [ l,  r- d_{lt} - degree_l] $ 的结点度数都会变为$ d_{lt} $ ,然后把r更新为$  r- d_{lt} - degree_l $。因此不难看出其实原来的 $ degree_l $ 是 $ d_{lt-1} $ 。然后就是 $ d_{rt} $ 的构造了。上面我们说每个r连到 l 有 $ d_n+2-l $的度,因此我们每次构造 $ d_{lt} $前,把 l 增加到(更新为)$ d_n+1-d_{rt} $ ,那么就能保证上述连边的这些r他们的度数为$ d_{rt} $。这样不断操作直到$ rt < lt $ 就能构造出符合要求的图。
 1 #include
 2 #define clr(x) memset(x,0,sizeof(x))
 3 #define mod 1000000007
 4 #define clr_1(x) memset(x,-1,sizeof(x))
 5 #define INF 0x3f3f3f3f
 6 #define LL long long
 7 #define pb push_back
 8 #define pbk pop_back
 9 using namespace std;
10 const int N=3e3+10;
11 int a[N];
12 vector<int> dt[N];
13 int rt,n,p,lt,r,l,ans;
14 int main()
15 {
16     scanf("%d",&n);
17     for(int i=1;i<=n;i++)
18         scanf("%d",a+i);
19     for(int i=1;i<=a[n]+1;i++)
20         dt[i].clear();
21     rt=n;
22     r=a[n]+1;
23     lt=1;
24     l=1;
25     while(lt<=rt)
26     {
27         while(dt[l].size()<a[lt])
28         {
29             for(int j=l;j)
30                 dt[j].pb(r);
31             r--;
32         }
33         rt--;
34         lt++;
35         l=a[n]+1-a[rt];
36     }
37     ans=0;
38     for(int i=1;i<=a[n]+1;i++)
39         ans+=dt[i].size();
40     printf("%d\n",ans);
41     for(int u=1;u<=a[n]+1;u++)
42     {
43         for(auto v:dt[u])
44             printf("%d %d\n",u,v);
45     }
46     return 0;
47 }
View Code

 

E. Well played!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:

Max owns n creatures, i-th of them can be described with two numbers — its health hpi and its damage dmgi. Max also has two types of spells in stock:

  1. Doubles health of the creature (hpi := hpi·2);
  2. Assigns value of health of the creature to its damage (dmgi := hpi).

Spell of first type can be used no more than a times in total, of the second type — no more than b times in total. Spell can be used on a certain creature multiple times. Spells can be used in arbitrary order. It isn't necessary to use all the spells.

Max is really busy preparing for his final exams, so he asks you to determine what is the maximal total damage of all creatures he can achieve if he uses spells in most optimal way.

Input

The first line contains three integers nab (1 ≤ n ≤ 2·105, 0 ≤ a ≤ 20, 0 ≤ b ≤ 2·105) — the number of creatures, spells of the first type and spells of the second type, respectively.

The i-th of the next n lines contain two number hpi and dmgi (1 ≤ hpi, dmgi ≤ 109) — description of the i-th creature.

Output

Print single integer — maximum total damage creatures can deal.

Examples
input
Copy
2 1 1
10 15
6 1
output
Copy
27
input
Copy
3 0 3
10 8
7 11
5 2
output
Copy
26



题意:你在打炉石玩脏牧,场上有n个单位。现在给你a张神圣之灵和b张心灵之火,让你营造出场上攻击总和最大的局面。并输出总攻击值。
题解:这题要暴力过。不知道非暴力为什么过不了。就是前缀和处理心火造成的攻击增加,然后模拟每一个单位翻倍后的情况,找最大的那个。由于这样做取最大值一定会用到心火(翻倍肯定更大),所以要特判一下b==0的情况。
 1 #include
 2 #define clr(x) memset(x,0,sizeof(x))
 3 #define mod 1000000007
 4 #define clr_1(x) memset(x,-1,sizeof(x))
 5 #define INF 0x3f3f3f3f
 6 #define LL long long
 7 #define pb push_back
 8 #define pbk pop_back
 9 using namespace std;
10 const int N=3e5+10;
11 struct node
12 {
13     LL hp,dmg,xc;
14 }skil[N];
15 LL pre[N];
16 LL sum,t,k,a,b,mul,ans,tmp;
17 int n,m;
18 bool cmp(node a,node b)
19 {
20     return a.xc>b.xc;
21 }
22 int main()
23 {
24     scanf("%d%I64d%I64d",&n,&a,&b);
25     mul=1<<a;
26     b=min(b,(LL)n);
27     sum=0;
28     for(int i=1;i<=n;i++)
29     {
30         scanf("%I64d%I64d",&skil[i].hp,&skil[i].dmg);
31         skil[i].xc=max(0LL,skil[i].hp-skil[i].dmg);
32         sum+=skil[i].dmg;
33     }
34     if(b==0)
35     {
36         printf("%I64d\n",sum);
37         return 0;
38     }
39     sort(skil+1,skil+n+1,cmp);
40     pre[0]=0;
41     for(int i=1;i<=n;i++)
42         pre[i]=pre[i-1]+skil[i].xc;
43     LL ans=sum+pre[b];
44     for(int i=1;i<=n;i++)
45     {
46         tmp=sum-skil[i].dmg+skil[i].hp*mul;
47         if(i<=b)
48             tmp+=pre[b]-skil[i].xc;
49         else
50             tmp+=pre[b-1];
51         ans=max(ans,tmp);
52     }
53     printf("%I64d\n",ans);
54     return 0;
55 }
View Code

 

F. 最大流
我:???最大流是什么

转载于:https://www.cnblogs.com/wujiechao/p/8979692.html

你可能感兴趣的:(Educational Codeforces Round 43 (Rated for Div. 2) ABCDE)