zoukankan      html  css  js  c++  java
  • 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
    %d %d 1 1
    ",n,m);
    22         for(i=1;i<=n;i++){
    23             if(i%2==1)
    24                 for(j=1;j<=m;j++)printf("%d %d
    ",i,j);
    25             else
    26                 for(j=m;j>0;j--)printf("%d %d
    ",i,j);
    27         }
    28         printf("1 1
    ");
    29     }
    30     else if(n%2==0){
    31         printf("0
    1 1
    ");
    32         for(i=1;i<=n;i++){
    33             if(i%2==1)
    34                 for(j=2;j<=m;j++)printf("%d %d
    ",i,j);
    35             else
    36                 for(j=m;j>1;j--)printf("%d %d
    ",i,j);
    37         }
    38         for(i=n;i>0;i--)printf("%d 1
    ",i);
    39     }
    40     else{
    41         printf("0
    1 1
    ");
    42         for(i=1;i<=m;i++){
    43             if(i%2==1)
    44                 for(j=2;j<=n;j++)printf("%d %d
    ",j,i);
    45             else
    46                 for(j=n;j>1;j--)printf("%d %d
    ",j,i);
    47         }
    48         for(i=m;i>0;i--)printf("1 %d
    ",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
    ",ans);
    44 }
    View Code
  • 相关阅读:
    【Python】 命名空间与LEGB规则
    【Python&数据结构】 抽象数据类型 Python类机制和异常
    【算法】 算法和数据结构绪论
    【网络】 数据链路层&物理层笔记
    svn -- svn图标解析
    svn -- svn数据仓库
    svn -- svn安装与配置
    svn -- svn简介
    mysql -- 远程访问mysql的解决方案
    css3 -- 自动生成序号(不使用JS,可任意排序)
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/10399657.html
Copyright © 2011-2022 走看看