Codeforces Beta Round #59 (Div. 2)

Codeforces Beta Round #59 (Div. 2)

http://codeforces.com/contest/63

A

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 1000006
 9 #define rep(k,i,j) for(int k=i;k<j;k++)
10 typedef long long ll;
11 typedef unsigned long long ull;
12 
13 struct sair{
14     string name,v;
15 }a[105];
16 
17 int main(){
18     #ifndef ONLINE_JUDGE
19         freopen("input.txt","r",stdin);
20     #endif
21     std::ios::sync_with_stdio(false);
22     int n;
23     cin>>n;
24     rep(i,1,n+1){
25         cin>>a[i].name>>a[i].v;
26     }
27     rep(i,1,n+1){
28         if(a[i].v=="rat"){
29             cout<<a[i].name<<endl;
30         }
31     }
32     rep(i,1,n+1){
33         if(a[i].v=="woman"||a[i].v=="child"){
34             cout<<a[i].name<<endl;
35         }
36     }
37     rep(i,1,n+1){
38         if(a[i].v=="man"){
39             cout<<a[i].name<<endl;
40         }
41     }
42     rep(i,1,n+1){
43         if(a[i].v=="captain"){
44             cout<<a[i].name<<endl;
45         }
46     }
47 }
View Code

B

暴力模拟即可

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 1000006
 9 #define rep(k,i,j) for(int k=i;k<j;k++)
10 typedef long long ll;
11 typedef unsigned long long ull;
12 
13 
14 int n,k;
15 int a[105];
16 int book[105];
17 
18 int main(){
19     #ifndef ONLINE_JUDGE
20       //  freopen("input.txt","r",stdin);
21     #endif
22     std::ios::sync_with_stdio(false);
23     cin>>n>>k;
24     int ans=0;
25     rep(i,1,n+1){
26         cin>>a[i];
27     }
28     a[0]=-0x3f3f3f3f;
29     sort(a,a+n+1);
30     int flag=1;
31     while(flag){
32         flag=0;
33         rep(i,1,n+1){
34             if(a[i]<k)
35             if(a[i]!=a[i-1]){
36                 book[i]++;
37                 flag=1;
38             }
39         }
40         rep(i,0,n+1) a[i]+=book[i],book[i]=0;
41         sort(a,a+n+1);
42         ans+=flag;
43     }
44     cout<<ans<<endl;
45 }
View Code

C

枚举1-9999的数,然后一个个判断,看看有几个符合条件

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 1000006
 9 #define rep(k,i,j) for(int k=i;k<j;k++)
10 typedef long long ll;
11 typedef unsigned long long ull;
12 
13 
14 int n;
15 struct sair{
16     int a,b,c;
17 }q[15];
18 
19 int main(){
20     #ifndef ONLINE_JUDGE
21       //  freopen("input.txt","r",stdin);
22     #endif
23    // std::ios::sync_with_stdio(false);
24     cin>>n;
25     rep(i,0,n) {
26         cin>>q[i].a>>q[i].b>>q[i].c;
27     }
28     int x,y,z;
29     int ans,num=0;
30     rep(i,0,10000){
31         int tmp=i;
32         int a,b,c,d;
33         a=tmp%10,tmp/=10;
34         b=tmp%10,tmp/=10;
35         c=tmp%10,tmp/=10;
36         d=tmp%10;
37         if(a==b||a==c||a==d||b==c||b==d||c==d) continue;
38         int flag=1;
39         rep(j,0,n){
40             x=0,y=0,z;
41             tmp=q[j].a;
42             z=tmp%10;
43             if(a==z) x++;
44             if(b==z) y++;
45             if(c==z) y++;
46             if(d==z) y++;
47             tmp/=10;
48             z=tmp%10;
49             if(b==z) x++;
50             if(a==z) y++;
51             if(c==z) y++;
52             if(d==z) y++;
53             tmp/=10;
54             z=tmp%10;
55             if(c==z) x++;
56             if(b==z) y++;
57             if(a==z) y++;
58             if(d==z) y++;
59             tmp/=10;
60             z=tmp%10;
61             if(d==z) x++;
62             if(b==z) y++;
63             if(c==z) y++;
64             if(a==z) y++;
65             if(x!=q[j].b||y!=q[j].c){
66                 flag=0;
67                 break;
68             }
69         }
70         if(flag){
71             num++;
72             ans=i;
73         }
74     }
75     if(num==0) cout<<"Incorrect data"<<endl;
76     else if(num==1) printf("%04d\n",ans);
77     else cout<<"Need more data"<<endl;
78 }
View Code

D

通过多次模拟可以发现,只要走S形即可

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 1000006
 9 #define rep(k,i,j) for(int k=i;k<j;k++)
10 typedef long long ll;
11 typedef unsigned long long ull;
12 
13 int field[55][105];
14 
15 int main(){
16     #ifndef ONLINE_JUDGE
17       //  freopen("input.txt","r",stdin);
18     #endif
19     std::ios::sync_with_stdio(false);
20     int a,b,c,d,n;
21     cin >> a >> b >> c >> d >> n;
22     for (int i=0; i<50; i++) {
23         for (int j=0; j<100; j++) {
24             field[i][j]=0;
25         }
26     }
27     int party[26]={0};
28     for (int i=0; i<n; i++) {
29         cin >> party[i];
30     }
31     for (int i=0; i<max(b,d); i++) {
32         for (int j=0; j<a+c; j++) {
33             if ((j<a&&i>=b)||(j>=a&&i>=d))field[i][j]='.';
34         }
35     }
36     int x=0,y=0,dx=1;
37     if (((b>d)&&(d%2==1))||((d>b)&&(b%2==0))){
38         x=a+c-1;dx=-1;
39     }
40     for (int i=0; i<n; i++) {
41         for (int j=0; j<party[i]; j++) {
42             field[y][x]='a'+i;
43             if (x+dx<0||x+dx>=a+c||field[y][x+dx]=='.') {
44                 dx*=-1;
45                 y++;
46             } else {
47                 x+=dx;
48             }
49         }
50     }
51     cout << "YES" << endl;
52     for (int i=0; i<max(b,d); i++) {
53         for (int j=0; j<a+c; j++) {
54             cout << char(field[i][j]);
55         }
56         cout << endl;
57     }
58 
59 }
View Code

E

一种类似博弈的题目,用状压表示每一种情况,然后搜索,找出Karlsson的必胜路径,找不到的话就是必败

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 1000006
 9 #define rep(k,i,j) for(int k=i;k<j;k++)
10 typedef long long ll;
11 typedef unsigned long long ull;
12 
13 const int N=19,S=1<<19;
14 
15 int Next[3][N]={{3,4,5,7,8,9,10,N,12,13,14,15,N,16,17,18,N,N,N},
16                       {1,2,N,4,5,6,N,8,9,10,11,N,13,14,15,N,17,18,N},
17                       {4,5,6,8,9,10,11,12,13,14,15,N,16,17,18,N,N,N,N}};
18 
19 int dp[S],status=0;
20 
21 int dfs(int now){
22     if(dp[now]) return dp[now];
23     rep(t,0,3){
24         rep(i,0,N){
25             int tmp=now,p=i;
26             while(tmp&(1<<p)){
27                 tmp^=(1<<p);
28                 if(dfs(tmp)==2){
29                     return dp[now]=1;
30                 }
31                 p=Next[t][p];
32             }
33         }
34     }
35     return dp[now]=2;
36 }
37 
38 int main(){
39     #ifndef ONLINE_JUDGE
40         freopen("input.txt","r",stdin);
41     #endif
42     std::ios::sync_with_stdio(false);
43     char ch;
44     rep(i,0,N){
45         cin>>ch;
46         if(ch=='.'||ch=='O'){
47             if(ch=='O'){
48                 status+=(1<<i);
49             }
50         }
51         else{
52             i--;
53         }
54     }
55     int flag=dfs(status);
56     if(flag==1) cout<<"Karlsson"<<endl;
57     else cout<<"Lillebror"<<endl;
58 }
View Code

猜你喜欢

转载自www.cnblogs.com/Fighting-sh/p/10453040.html