Codeforces Beta Round #35 (Div. 2)

Codeforces Beta Round #35 (Div. 2)

http://codeforces.com/contest/35

A

这场的输入输出是到文件中的,不是标准的输入输出。。。没注意看,RE了好久。。。

 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 eps 1e-8
 8 #define PI acos(-1.0)
 9 #define maxn 1000005
10 typedef long long ll;
11 typedef unsigned long long ull;
12
13 /*#ifndef ONLINE_JUDGE
14         freopen("1.txt","r",stdin);
15 #endif */
16
17 ifstream cinn("input.txt");
18 ofstream coutt("output.txt");
19
20 int main(){
21     #ifndef ONLINE_JUDGE
22      //   freopen("1.txt","r",stdin);
23     #endif
24     std::ios::sync_with_stdio(false);
25     int u,v;
26     int b;
27
28     int a[15];
29     memset(a,0,sizeof(a));
30     cinn>>b;
31     a[b]=1;
32     for(int i=0;i<3;i++){
33         cinn>>u>>v;
34         swap(a[u],a[v]);
35     }
36     for(int i=1;i<=3;i++){
37         if(a[i]==1){
38             coutt<<i;
39             return 0;
40         }
41     }
42     return 0;
43 }

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 eps 1e-8
 8 #define PI acos(-1.0)
 9 #define maxn 1000005
10 typedef long long ll;
11 typedef unsigned long long ull;
12
13 /*#ifndef ONLINE_JUDGE
14         freopen("1.txt","r",stdin);
15 #endif */
16 string s,t,x[31][31];
17 int n,m,k,i,j,a,b,o,r;
18
19 int main(){
20   //  #ifndef ONLINE_JUDGE
21         freopen ("input.txt","r",stdin);
22         freopen ("output.txt","w",stdout);
23    // #endif
24     cin>>n>>m>>k;
25     for (o=1;o<=k;o++){
26         cin>>s;
27         if (s[0]==‘+‘){
28             cin>>a>>b>>t;
29             while (1){
30                 if (x[a][b]==""){
31                     x[a][b]=t;
32                     break;
33                 }
34                 else {
35                     b++;
36                     if (b>m){
37                         a++;
38                         b=1;
39                         if (a>n)
40                             break;
41                     }
42                 }
43             }
44         }
45         else {
46             cin>>t;
47             r=0;
48             for (i=1;i<=n;i++){
49                 if (r==1)
50                     break;
51                 for (j=1;j<=m;j++){
52                     if (x[i][j]==t){
53                         r=1;
54                         break;
55                     }
56
57                 }
58             }
59             if (r==0){
60                 cout<<-1<<" "<<-1<<endl;
61             }
62             else {
63                 cout<<i-1<<" "<<j<<endl;
64                 x[i-1][j]="";
65             }
66         }
67     }
68 }

C

bfs

 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 eps 1e-8
 8 #define PI acos(-1.0)
 9 #define maxn 1000005
10 typedef long long ll;
11 typedef unsigned long long ull;
12
13 /*#ifndef ONLINE_JUDGE
14         freopen("1.txt","r",stdin);
15 #endif */
16 int book[2005][2005];
17 int n,m,k;
18 struct sair{
19     int x,y,step;
20 };
21 int dir[4][2]={0,1,1,0,0,-1,-1,0};
22
23 int main(){
24   //  #ifndef ONLINE_JUDGE
25         freopen ("input.txt","r",stdin);
26         freopen ("output.txt","w",stdout);
27    // #endif
28     cin>>n>>m>>k;
29     int x,y;
30     queue<sair>Q;
31     sair s,e;
32     for(int i=1;i<=k;i++){
33         cin>>x>>y;
34         s.x=x,s.y=y,s.step=1;
35         book[x][y]=1;
36         Q.push(s);
37     }
38     int last=1;
39     while(!Q.empty()){
40         s=Q.front();
41         Q.pop();
42         for(int i=0;i<4;i++){
43             e.x=s.x+dir[i][0];
44             e.y=s.y+dir[i][1];
45             if(e.x>=1&&e.x<=n&&e.y>=1&&e.y<=m&&!book[e.x][e.y]){
46                 e.step=s.step+1;
47                 if(e.step>last) last=e.step;
48             //    cout<<last<<endl;
49                 book[e.x][e.y]=e.step;
50                 Q.push(e);
51             }
52         }
53     }
54     for(int i=1;i<=n;i++){
55         for(int j=1;j<=m;j++){
56             if(book[i][j]==last){
57                 cout<<i<<" "<<j<<endl;
58                 return 0;
59             }
60         }
61     }
62 }

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 eps 1e-8
 8 #define PI acos(-1.0)
 9 #define maxn 1000005
10 typedef long long ll;
11 typedef unsigned long long ull;
12
13 /*#ifndef ONLINE_JUDGE
14         freopen("1.txt","r",stdin);
15 #endif */
16
17 int n,x;
18 int a[105];
19
20 int main(){
21   //  #ifndef ONLINE_JUDGE
22         freopen ("input.txt","r",stdin);
23         freopen ("output.txt","w",stdout);
24    // #endif
25     cin>>n>>x;
26     for(int i=1;i<=n;i++){
27         cin>>a[i];
28         a[i]=a[i]*(n-i+1);
29     }
30     sort(a+1,a+n+1);
31     for(int i=1;i<=n;i++){
32         x-=a[i];
33         if(x<0){
34             cout<<i-1<<endl;
35             return 0;
36         }
37
38     }
39     cout<<n<<endl;
40 }

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 eps 1e-8
 8 #define PI acos(-1.0)
 9 #define maxn 1000005
10 typedef long long ll;
11 typedef unsigned long long ull;
12
13 /*#ifndef ONLINE_JUDGE
14         freopen("1.txt","r",stdin);
15 #endif */
16
17 int n;
18 multiset<int>ms;
19 vector<pair<int,int> >ve,ans;
20
21
22 int main(){
23   //  #ifndef ONLINE_JUDGE
24         freopen ("input.txt","r",stdin);
25         freopen ("output.txt","w",stdout);
26    // #endif
27     std::ios::sync_with_stdio(false);
28     cin>>n;
29     int l,r,h;
30     for(int i=0;i<n;i++){
31         cin>>h>>l>>r;
32         ve.push_back(make_pair(l,h));
33         ve.push_back(make_pair(r,-h));
34     }
35     sort(ve.begin(),ve.end());
36     int i=0,j;
37     h=0;
38     ms.insert(h);
39     while(i<ve.size()){
40         j=i;
41         do{
42             if(ve[j].second>0){
43                 ms.insert(ve[j].second);
44             }
45             else{
46                 ms.erase(ms.find(-ve[j].second));
47             }
48             j++;
49
50         }while(j<ve.size()&&ve[i].first==ve[j].first);
51         if(h!=*ms.rbegin()){
52             ans.push_back(make_pair(ve[i].first,h));
53             ans.push_back(make_pair(ve[i].first,h=*ms.rbegin()));
54         }
55         i=j;
56     }
57     cout<<ans.size()<<endl;
58     for(int i=0;i<ans.size();i++){
59         cout<<ans[i].first<<" "<<ans[i].second<<endl;
60     }
61 }

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

时间: 2024-07-31 13:10:08

Codeforces Beta Round #35 (Div. 2)的相关文章

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

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 t

Codeforces Beta Round #14 (Div. 2)

Codeforces Beta Round #14 (Div. 2) http://codeforces.com/contest/14 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 500005