zoukankan      html  css  js  c++  java
  • Codeforces Beta Round #12 (Div 2 Only)

    Codeforces Beta Round #12 (Div 2 Only)

    http://codeforces.com/contest/12

    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 maxn 1000010
     7 typedef long long ll;
     8 /*#ifndef ONLINE_JUDGE
     9         freopen("1.txt","r",stdin);
    10 #endif */
    11 
    12 string str[5];
    13 
    14 int main(){
    15     #ifndef ONLINE_JUDGE
    16         freopen("1.txt","r",stdin);
    17     #endif
    18     for(int i=0;i<3;i++){
    19         cin>>str[i];
    20     }
    21     for(int i=0;i<3;i++){
    22         for(int j=0;j<3;j++){
    23             if(str[i][j]!=str[2-i][2-j]){
    24                 cout<<"NO"<<endl;
    25                 return 0;
    26             }
    27         }
    28     }
    29     cout<<"YES"<<endl;
    30 
    31 
    32     return 0;
    33 }
    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 maxn 1000010
     7 typedef long long ll;
     8 /*#ifndef ONLINE_JUDGE
     9         freopen("1.txt","r",stdin);
    10 #endif */
    11 
    12 string str[5];
    13 int ch[15];
    14 
    15 int main(){
    16     #ifndef ONLINE_JUDGE
    17      //   freopen("1.txt","r",stdin);
    18     #endif
    19     string str1,str2,ans="";
    20     cin>>str1>>str2;
    21     for(int i=0;i<str1.length();i++){
    22         ch[str1[i]-'0']++;
    23     }
    24     for(int i=1;i<10;i++){
    25         if(ch[i]){
    26             ans+=char(i+'0');
    27             ch[i]--;
    28             break;
    29         }
    30     }
    31 
    32     for(int i=0;i<10;i++){
    33         for(int j=0;j<ch[i];j++){
    34             ans+=char(i+'0');
    35         }
    36     }
    37    // cout<<ans<<" "<<str2<<endl;
    38     if(ans==str2) cout<<"OK"<<endl;
    39     else cout<<"WRONG_ANSWER"<<endl;
    40     return 0;
    41 }
    View Code

    C

    水题

     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 maxn 1000010
     7 typedef long long ll;
     8 /*#ifndef ONLINE_JUDGE
     9         freopen("1.txt","r",stdin);
    10 #endif */
    11 
    12 int n,m;
    13 map<string,int>mp;
    14 
    15 int a[105];
    16 bool cmp1(int a,int b){
    17     return a>b;
    18 }
    19 
    20 bool cmp2(int a,int b){
    21     return a<b;
    22 }
    23 
    24 bool cmp(pair<int,string>a,pair<int,string>b){
    25     return a.first>b.first;
    26 }
    27 
    28 vector<pair<int,string> >ve;
    29 
    30 int main(){
    31     #ifndef ONLINE_JUDGE
    32         freopen("1.txt","r",stdin);
    33     #endif
    34     cin>>n>>m;
    35     string str;
    36     for(int i=0;i<n;i++) cin>>a[i];
    37     for(int i=0;i<m;i++){
    38         cin>>str;
    39         mp[str]++;
    40     }
    41     map<string,int>::iterator it;
    42     for(it=mp.begin();it!=mp.end();it++){
    43         ve.push_back(make_pair(it->second,it->first));
    44     }
    45     sort(a,a+n,cmp2);
    46     int ans1=0,ans2=0;
    47     sort(ve.begin(),ve.end(),cmp);
    48    /* for(int i=0;i<ve.size();i++){
    49         cout<<ve[i].first<<" "<<ve[i].second<<endl;
    50     }*/
    51     for(int i=0;i<ve.size();i++){
    52         ans1+=ve[i].first*a[i];
    53     }
    54     sort(a,a+n,cmp1);
    55     for(int i=0;i<ve.size();i++){
    56         ans2+=ve[i].first*a[i];
    57     }
    58     cout<<ans1<<" "<<ans2<<endl;
    59 
    60 }
    View Code

    D

    线段树好题

    题意:n个女性比三种属性,一旦有一个女的三种属性都被另一个女的压制,那这个女的会自杀,问多少女性会自杀

    思路:

    先按第一个属性从大到小严格排序,然后再把第二个属性离散化作为线段树的下标,最后再把第三个属性作为线段树上的值,然后查询最大值即可

    如果第一个属性有相等的情况,需要把相等的情况全部比较完再更新

      1 #include <cstdio>
      2 #include <iostream>
      3 #include <cstring>
      4 #include <algorithm>
      5 #define lson num<<1,s,mid
      6 #define rson num<<1|1,mid+1,e
      7 #define maxn 500005
      8 
      9 using namespace std;
     10 
     11 struct node
     12 {
     13     int a,b,c;
     14     bool operator < (const node &cmp)const
     15     {
     16         if(a!=cmp.a)return a<cmp.a;
     17         if(b!=cmp.b)return b<cmp.b;
     18         return c<cmp.c;
     19     }
     20 }wm[maxn];
     21 
     22 int res[maxn<<2];
     23 int x[maxn];
     24 
     25 void pushup(int num)
     26 {
     27     res[num]=max(res[num<<1],res[num<<1|1]);
     28 }
     29 void build(int num,int s,int e)
     30 {
     31     res[num]=-1;
     32     if(s==e)return ;
     33     int mid=(s+e)>>1;
     34     build(lson);build(rson);
     35 }
     36 void update(int num,int s,int e,int pos,int val)
     37 {
     38     if(s==e)
     39     {
     40         res[num]=max(res[num],val);
     41         return;
     42     }
     43     int mid=(s+e)>>1;
     44     if(pos<=mid)update(lson,pos,val);
     45     else update(rson,pos,val);
     46     pushup(num);
     47 }
     48 int query(int num,int s,int e,int l,int r)
     49 {
     50     if(l<=s  && r>=e)return res[num];
     51     int mid=(s+e)>>1;
     52     if(r<=mid)return query(lson,l,r);
     53     else if(l>mid)return query(rson,l,r);
     54     else return max(query(lson,l,mid),query(rson,mid+1,r));
     55 }
     56 int main()
     57 {
     58     int n;
     59     scanf("%d",&n);
     60     for(int i=1;i<=n;i++)
     61         scanf("%d",&wm[i].a);
     62     for(int i=1;i<=n;i++)
     63     {
     64         scanf("%d",&wm[i].b);
     65         x[i]=wm[i].b;
     66     }
     67     for(int i=1;i<=n;i++)
     68         scanf("%d",&wm[i].c);
     69 
     70     sort(wm+1,wm+1+n);
     71 
     72     sort(x+1,x+1+n);
     73 
     74     int m=unique(x+1,x+1+n)-x;
     75     m--;
     76 
     77     int last=wm[n].a;
     78     int r=n;
     79     int l=n;
     80     int ans=0;
     81 
     82     wm[0].a=0x3f3f3f3f;
     83 
     84     for(int i=n;i>=1;)
     85     {
     86         while(wm[l].a==last)
     87         {
     88             l--;
     89         }
     90         int c=r;
     91         while(c>l)
     92         {
     93             int pos=lower_bound(x+1,x+m+1,wm[c].b)-x;
     94             if(pos+1<=m && query(1,1,m,pos+1,m)>wm[c].c)ans++;
     95             c--;
     96         }
     97         c=r;
     98         while(c>l)
     99         {
    100             int pos=lower_bound(x+1,x+m+1,wm[c].b)-x;
    101             update(1,1,m,pos,wm[c].c);
    102             c--;
    103         }
    104         i=l;r=l;last=wm[i].a;
    105     }
    106     printf("%d
    ",ans);
    107     return 0;
    108 }
    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 maxn 1000010
     7 typedef long long ll;
     8 /*#ifndef ONLINE_JUDGE
     9         freopen("1.txt","r",stdin);
    10 #endif */
    11 
    12 int book[1005][1005];
    13 
    14 int main(){
    15     #ifndef ONLINE_JUDGE
    16       //  freopen("1.txt","r",stdin);
    17     #endif
    18     int n;
    19     std::ios::sync_with_stdio(false);
    20     cin>>n;
    21      for(int i  = 0 ; i < n-1 ; i++){
    22          for(int j = 0 ; j < n-1 ; j++)
    23              book[i][j] = (i+j)%(n-1)+1;
    24      }
    25      for(int i = 0 ; i < n ; i++){
    26          book[i][n-1] = book[i][i];
    27          book[n-1][i] = book[i][i];
    28          book[i][i] = 0;
    29      }
    30      for(int i = 0 ; i < n ; i++){
    31          for(int j = 0 ; j < n ; j++)
    32              cout<<book[i][j]<<" ";
    33          cout<<endl;
    34      }
    35 
    36 }
    View Code
  • 相关阅读:
    webpack中的extract-text-webpack-plugin插件使用方法总结
    vue知识总结第一篇vue组件的定义以及父子组件的传值。
    Java在当前时间的基础上增加N时间
    SVN服务器端和客户端的搭建与使用
    字符串后面去0、补0
    安装Oracle数据库并建立可以用的用户
    【品优购代码外笔记】安装并使用Zookeeper
    【十次方基础教程(后台)】influxDB、cAdvisor、cAdvisor的安装与使用(监控微服务内存,自动扩容)
    【十次方基础教程(后台)】使用Rancher管理容器
    【十次方基础教程(后台)】使用Gogs,Jenkins实现持续集成
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/10352997.html
Copyright © 2011-2022 走看看