Codeforces Round #222 (Div. 2)

来源:互联网 发布:股票模拟训练软件 编辑:程序博客网 时间:2024/06/10 02:15
A. Playing with Dice

Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.

The first player wrote number a, the second player wrote numberb. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?

Input

The single line contains two integers a andb (1 ≤ a, b ≤ 6) — the numbers written on the paper by the first and second player, correspondingly.

Output

Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.

Sample test(s)
Input
2 5
Output
3 0 3
Input
2 4
Output
2 1 3
Note

The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.

You can assume that number a is closer to numberx than numberb, if|a - x| < |b - x|.

题意:两个人先写一个数,然后掷筛子,谁挨着近谁赢,问赢,平个有多少种情况

注意两个人猜的数字相等的情况

#include<iostream>using namespace std;int numa,numb,numdraw;int a,b;int cntdraw(){    return !((a+b)%2);}int cnta(){    return a<b?((a+b)/2-numdraw):(6-(a+b)/2);}int cntb(){    return a>b?((a+b)/2-numdraw):(6-(a+b)/2);}int main(){    cin>>a>>b;    if(a==b)    {        cout<<0<<' '<<6<<' '<<0<<endl;        return 0;    }    numa=numb=numdraw=0;    numdraw=cntdraw();    numa=cnta();    numb=cntb();    cout<<numa<<' '<<numdraw<<' '<<numb<<endl;}

B. Semifinals

Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choosek people (0 ≤ 2k ≤ n) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the topk in their semifinal but got to then - 2k of the best among the others.

The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of participants in each semifinal.

Each of the next n lines contains two integersai andbi (1 ≤ ai, bi ≤ 109) — the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequencesa1,a2, ..., an andb1,b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.

Output

Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. Thei-th character in thej-th line should equal "1" if thei-th participant of thej-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".

Sample test(s)
Input
49840 99209860 99809930 1002010040 10090
Output
11101100
Input
49900 98509940 993010000 1002010060 10110
Output
11001100
Note

Consider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090.

  • If k = 0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals.
  • If k = 1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds).
  • If k = 2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>using namespace std;const int maxn=1000010;int one[maxn],two[maxn];void print(int k,int n){    for(int i=0;i<=k;i++)    printf("1");    for(int i=k+1;i<n;i++)    printf("0");}int main(){    int n;    scanf("%d",&n);    for(int i=0;i<n;i++)    scanf("%d%d",&one[i],&two[i]);    int i=0,j=0,num=0;    while(num<n)    {        if(one[i]<two[j])        i++;        else j++;        num++;    }    int k=max(i-1,n/2-1);    print(k,n);    puts("");    k=max(j-1,n/2-1);    print(k,n);    return 0;}

C. Maze

Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.

Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactlyk empty cells into walls so that all the remaining cells still formed a connected area. Help him.

Input

The first line contains three integers n,m,k (1 ≤ n, m ≤ 500,0 ≤ k < s), wheren and m are the maze's height and width, correspondingly,k is the number of walls Pavel wants to add and letters represents the number of empty cells in the original maze.

Each of the next n lines contains m characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.

Output

Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").

It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.

Sample test(s)
Input
3 4 2#..#..#.#...
Output
#.X#X.#.#...
Input
5 4 5#...#.#..#.....#.#.#
Output
#XXX#X#.X#.....#.#.#
题意:给你一个迷宫,把其中的k个空地变成墙,是迷宫还是联通的

dfs一遍把剩余的空地标记一下。

#include<iostream>#include<cstring>#include<cstdio>using namespace std;const int maxn=550;int n,m,k,num;char grid[maxn][maxn];int s,e;int dx[]= {1,-1,0,0};int dy[]= {0,0,1,-1};int cnt;void dfs(int x,int y){    if(cnt>=num-k)        return;    grid[x][y]='X';    for(int i=0; i<4; i++)    {        int tx=x+dx[i],ty=y+dy[i];        if(tx>=0&&tx<n&&ty>=0&&ty<m&&grid[tx][ty]=='.')        {            cnt++;            dfs(tx,ty);        }    }}void print(){    for(int i=0; i<n; i++)    {        for(int j=0; j<m; j++)            if(grid[i][j]=='.') cout<<'X';            else if(grid[i][j]=='X')cout<<'.';            else cout<<grid[i][j];        cout<<endl;    }}int main(){    scanf("%d%d%d",&n,&m,&k);    num=0;    getchar();    for(int i=0; i<n; i++)    {        scanf("%s",grid[i]);        //cout<<grid[i]<<endl;        getchar();    }    for(int i=0; i<n; i++)        for(int j=0; j<m; j++)            if(grid[i][j]=='.')            {                num++,s=i,e=j;            }    cnt=0;    dfs(s,e);    print();    return 0;}
D. Preparing for the Contest

Soon there will be held the world's largest programming contest, but the testing system still hasm bugs. The contest organizer, a well-known university, has no choice but to attract university students to fix all the bugs. The university hasn students able to perform such work. The students realize that they are the only hope of the organizers, so they don't want to work for free: thei-th student wants to get ci 'passes' in his subjects (regardless of the volume of his work).

Bugs, like students, are not the same: every bug is characterized by complexityaj, and every student has the level of his abilitiesbi. Studenti can fix a bug j only if the level of his abilities is not less than the complexity of the bug:bi ≥ aj, and he does it in one day. Otherwise, the bug will have to be fixed by another student. Of course, no student can work on a few bugs in one day. All bugs are not dependent on each other, so they can be corrected in any order, and different students can work simultaneously.

The university wants to fix all the bugs as quickly as possible, but giving the students the total of not more thans passes. Determine which students to use for that and come up with the schedule of work saying which student should fix which bug.

Input

The first line contains three space-separated integers: n, m and s (1 ≤ n, m ≤ 105,0 ≤ s ≤ 109) — the number of students, the number of bugs in the system and the maximum number of passes the university is ready to give the students.

The next line contains m space-separated integersa1, a2, ..., am (1 ≤ ai ≤ 109) — the bugs' complexities.

The next line contains n space-separated integersb1, b2, ..., bn (1 ≤ bi ≤ 109) — the levels of the students' abilities.

The next line contains n space-separated integersc1, c2, ..., cn (0 ≤ ci ≤ 109) — the numbers of the passes the students want to get for their help.

Output

If the university can't correct all bugs print "NO".

Otherwise, on the first line print "YES", and on the next line printm space-separated integers: the i-th of these numbers should equal the number of the student who corrects thei-th bug in the optimal answer. The bugs should be corrected as quickly as possible (you must spend the minimum number of days), and the total given passes mustn't exceeds. If there are multiple optimal answers, you can output any of them.

Sample test(s)
Input
3 4 91 3 1 22 1 34 3 6
Output
YES2 3 2 3
Input
3 4 102 3 1 22 1 34 3 6
Output
YES1 3 1 3
Input
3 4 92 3 1 22 1 34 3 6
Output
YES3 3 2 3
Input
3 4 51 3 1 22 1 35 3 6
Output
NO
Note

Consider the first sample.

The third student (with level 3) must fix the 2nd and 4th bugs (complexities 3 and 2 correspondingly) and the second student (with level 1) must fix the 1st and 3rd bugs (their complexity also equals 1). Fixing each bug takes one day for each student, so it takes 2 days to fix all bugs (the students can work in parallel).

The second student wants 3 passes for his assistance, the third student wants 6 passes. It meets the university's capabilities as it is ready to give at most 9 passes.


题意:有n个人,m个病毒,s张通行证,然后给出m个病毒的等级,n个人的等级,以及n个人去杀病毒所需要的pass数量,问所最少花费几天可以杀光病毒,并输出每个病毒被那一个人所清理。PS:人要杀病毒必须等级大于等于病毒,一个人只需支付一次pass。
刚开始有点思路,但有的地方没想通,参考了别人的代码

#include<iostream>#include<algorithm>#include<queue>#include<cstdio>using namespace std;const int maxn=100010;struct node{    int abi,pass,id;    friend bool operator<(const node &a,const node &b)    {        return a.pass>b.pass;    }};node stu[maxn],vir[maxn];int N,M,S;bool cmp(node a,node b){    return a.abi>b.abi;}bool can(int mid){    int b=1,sum=S,i=1;    priority_queue<node> q;    while(b<=M)    {        for(;i<=N;i++)        {            if(stu[i].abi>=vir[b].abi)//每次找比他大的入队            q.push(stu[i]);            else break;        }        if(q.empty()) return false;        node tmp=q.top();        q.pop();        if(sum<tmp.pass) return false;        sum-=tmp.pass;        b+=mid;//这个大的可以连续工作mid天,消灭mid个病毒    }    return true;}void put(int ans){    int i=1,b=1;    int who[maxn];    priority_queue<node> q;    while(b<=M)    {        for(;i<=N;i++)        {            if(stu[i].abi>=vir[b].abi)            q.push(stu[i]);            else break;        }        node tmp=q.top();        q.pop();        int t=min(M,b+ans-1);        for(int k=b;k<=t;k++)        who[vir[k].id]=tmp.id;        if(t>=M) break;        b+=ans;    }    bool first=true;    for(int i=1;i<=M;i++)    {        if(first){cout<<who[i];first=false;}        else cout<<" "<<who[i];    }    cout<<endl;}int main(){    cin>>N>>M>>S;    for(int i=1;i<=M;i++){scanf("%d",&vir[i].abi);vir[i].id=i;}    for(int i=1;i<=N;i++){scanf("%d",&stu[i].abi);stu[i].id=i;}    for(int i=1;i<=N;i++)scanf("%d",&stu[i].pass);    sort(vir+1,vir+1+M,cmp);    sort(stu+1,stu+1+N,cmp);    if(!can(M))    {        cout<<"NO"<<endl;        return 0;    }    int l=0,r=M,mid;    while(l<r)    {        mid=(l+r)/2;        if(can(mid)) r=mid;        else l=mid+1;    }    cout<<"YES"<<endl;    put(l);    return 0;}


0 0
原创粉丝点击