Codeforces Beta Round #42 (Div. 2)

Codeforces Beta Round #42 (Div. 2)

http://codeforces.com/contest/43

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 maxn 1000005
 8 typedef long long ll;
 9 typedef unsigned long long ull;
10 
11 string str;
12 map<string,int>mp;
13 
14 int main(){
15     #ifndef ONLINE_JUDGE
16       //  freopen("input.txt","r",stdin);
17     #endif
18     std::ios::sync_with_stdio(false);
19     int n;
20     cin>>n;
21     for(int i=1;i<=n;i++){
22         cin>>str;
23         mp[str]++;
24     }
25     string ans;
26     int Max=0;
27     for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++){
28         if(Max < it->second){
29             Max = it->second;
30             ans = it->first;
31         }
32     }
33     cout<<ans<<endl;
34 }
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 maxn 1000005
 8 typedef long long ll;
 9 typedef unsigned long long ull;
10 
11 string s1,s2;
12 map<char,int>mp;
13 
14 int main(){
15     #ifndef ONLINE_JUDGE
16         freopen("input.txt","r",stdin);
17     #endif
18     std::ios::sync_with_stdio(false);
19     getline(cin,s1);
20     getline(cin,s2);
21     for(int i=0;i<s1.length();i++){
22         mp[s1[i]]++;
23     }
24     int flag=0;
25     for(int i=0;i<s2.length();i++){
26         if(s2[i]==' ') continue;
27         if(mp[s2[i]]){
28             mp[s2[i]]--;
29         }
30         else{
31             flag=1;
32         }
33     }
34     if(!flag) cout<<"YES"<<endl;
35     else cout<<"NO"<<endl;
36 
37 }
View Code

 

C

cf的评测机是真的快。。。写了个n^2的假算法都过了。。。正解应该是:sum(num%3==0)/2+min(sum(num%3==1),sum(num%3==2))

 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 maxn 1000005
 8 typedef long long ll;
 9 typedef unsigned long long ull;
10 
11 ll a[10005];
12 
13 int book[10005];
14 
15 bool Check(ll a,ll b){
16     ll tmpa=a;
17     ll tmpb=b;
18     while(tmpa){
19         tmpb=tmpb*10+tmpa%10;
20         tmpa/=10;
21     }
22     if(tmpb%3==0) return true;
23     tmpa=a;
24     tmpb=b;
25     while(tmpb){
26         tmpa=tmpa*10+tmpb%10;
27         tmpb/=10;
28     }
29     if(tmpa%3==0) return true;
30     return false;
31 }
32 
33 int main(){
34     #ifndef ONLINE_JUDGE
35      //   freopen("input.txt","r",stdin);
36     #endif
37     std::ios::sync_with_stdio(false);
38     int n;
39     cin>>n;
40     for(int i=1;i<=n;i++) cin>>a[i];
41     int ans=0;
42     for(int i=1;i<=n;i++){
43         if(!book[i]){
44             for(int j=i+1;j<=n;j++){
45                 if(!book[j])
46                 if(Check(a[i],a[j])){
47                     ans++;
48                     book[j]=1;
49                     break;
50                 }
51             }
52         }
53     }
54     cout<<ans<<endl;
55 
56 }
View Code

 

D

模拟

 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 maxn 1000005
 8 typedef long long ll;
 9 typedef unsigned long long ull;
10 
11 
12 
13 int main(){
14     #ifndef ONLINE_JUDGE
15      //   freopen("input.txt","r",stdin);
16     #endif
17     std::ios::sync_with_stdio(false);
18     int n,m,i,j;
19     scanf("%d%d",&n,&m);
20     if((n%2==1&&m%2==1)||(n==1&&m>2)||(m==1&&n>2)){
21         printf("1\n%d %d 1 1\n",n,m);
22         for(i=1;i<=n;i++){
23             if(i%2==1)
24                 for(j=1;j<=m;j++)printf("%d %d\n",i,j);
25             else
26                 for(j=m;j>0;j--)printf("%d %d\n",i,j);
27         }
28         printf("1 1\n");
29     }
30     else if(n%2==0){
31         printf("0\n1 1\n");
32         for(i=1;i<=n;i++){
33             if(i%2==1)
34                 for(j=2;j<=m;j++)printf("%d %d\n",i,j);
35             else
36                 for(j=m;j>1;j--)printf("%d %d\n",i,j);
37         }
38         for(i=n;i>0;i--)printf("%d 1\n",i);
39     }
40     else{
41         printf("0\n1 1\n");
42         for(i=1;i<=m;i++){
43             if(i%2==1)
44                 for(j=2;j<=n;j++)printf("%d %d\n",j,i);
45             else
46                 for(j=n;j>1;j--)printf("%d %d\n",j,i);
47         }
48         for(i=m;i>0;i--)printf("1 %d\n",i);
49     }
50 
51 }
View Code

 

E

模拟

 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 maxn 1000005
 8 typedef long long ll;
 9 typedef unsigned long long ull;
10 
11 
12 int n,s,t[505][505],k[505],v[505][505],ans;
13 
14 int main(){
15     #ifndef ONLINE_JUDGE
16      //   freopen("input.txt","r",stdin);
17     #endif
18     std::ios::sync_with_stdio(false);
19     scanf("%d%d",&n,&s);
20     for (int i=1;i<=n;i++){
21         scanf("%d",&k[i]);
22         for (int j=1;j<=k[i];j++){
23             scanf("%d%d",&v[i][j],&t[i][j]);
24             t[i][j]+=t[i][j-1];
25             t[i][k[i]+1]=1<<30;
26         }
27     }
28     for (int i=1;i<n;i++)
29         for (int j=i+1;j<=n;j++){
30             int t1=1,t2=1,x1=0,x2=0,tmp=0,tmp2=-1;
31             while (t1<=k[i] || t2<=k[j]){
32                 int tmp1=min(t[i][t1],t[j][t2]);
33                 x1+=(tmp1-tmp)*v[i][t1];
34                 x2+=(tmp1-tmp)*v[j][t2];
35                 if (t[i][t1]<t[j][t2])  t1++;else t2++;
36                 if (x1>x2 && tmp2==0)   ans++;
37                 if (x1<x2 && tmp2==1)   ans++;
38                 if (x1>x2)  tmp2=1;
39                 if (x1<x2)  tmp2=0;
40                 tmp=tmp1;
41             }
42         }
43     printf("%d\n",ans);
44 }
View Code

 

posted on 2019-02-19 10:47  Fighting_sh  阅读(158)  评论(0编辑  收藏  举报

导航