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 }

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 }

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 }

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\n",ans);
107     return 0;
108 }

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 }

原文地址:https://www.cnblogs.com/Fighting-sh/p/10352997.html

时间: 2024-10-27 08:01:33

Codeforces Beta Round #12 (Div 2 Only)的相关文章

Codeforces Beta Round #12 (Div 2 Only) D. Ball 树状数组查询后缀、最值

http://codeforces.com/problemset/problem/12/D 这里的BIT查询,指的是查询[1, R]或者[R, maxn]之间的最值,这样就够用了. 设三个权值分别是b[1], b[2], b[2]; 首先,先把b[1]值离散化,离散成一个个id,那么只能是在id比较大的地方找了.然后把b[2]排序,倒序查询,也就是先查询最大的,当然它是没可能自杀的,因为它已经最大了,然后查询完后,把它压进bit后,以后在bit查询,就不需要管b[2]了,因为在bit里面的b[2

Codeforces Beta Round #12 (Div 2 Only) D. Ball sort/map

D. Ball Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/12/D Description N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master

Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array

E. Lucky Array Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467are not. Petya has an arra

暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table

题目传送门 1 /* 2 题意:求最大矩形(全0)的面积 3 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 4 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 5 详细解释:http://www.cnblogs.com/cszlg/p/3217478.html 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <cstring> 10 #include <cmath>

图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces

题目传送门 1 /* 2 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <algorithm> 7 #include <cmath> 8 using namespace std; 9 10 const int MAXN = 1e2 + 10; 11 const int INF = 0x3f3f3

BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues

题目传送门 1 /* 2 BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到.因为雕像最多8步就会全部下落, 3 只要撑过这个时间就能win,否则lose 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <queue> 8 #include <vector> 9 #include <cstring> 10 using namespace std; 11 1

水题 Codeforces Beta Round #70 (Div. 2) A. Haiku

题目传送门 1 /* 2 水题:三个字符串判断每个是否有相应的元音字母,YES/NO 3 下午网速巨慢:( 4 */ 5 #include <cstdio> 6 #include <cstring> 7 #include <string> 8 #include <iostream> 9 #include <algorithm> 10 #include <cmath> 11 using namespace std; 12 13 cons

Codeforces Beta Round #6 (Div. 2 Only)

Codeforces Beta Round #6 (Div. 2 Only) 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

Codeforces Beta Round #9 (Div. 2 Only)

Codeforces Beta Round #9 (Div. 2 Only) http://codeforces.com/contest/9 A gcd水题 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