Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)

https://codeforces.com/contest/1064

A

 1 #include<bits/stdc++.h>
 2 #define pb push_back
 3 using namespace std;
 4
 5 bool Check(int a,int b,int c){
 6     if(a+b>c&&b+c>a&&a+c>b) return true;
 7     return false;
 8 }
 9
10 int main(){
11     int a,b,c;
12     cin>>a>>b>>c;
13     if(Check(a,b,c)){
14         cout<<0<<endl;
15     }
16     else{
17         cout<<min(abs(a+b-c),min(abs(b+c-a),abs(a+c-b)))+1<<endl;
18
19     }
20 }

B

打表找规律

 1 #include<bits/stdc++.h>
 2 #define pb push_back
 3 typedef long long ll;
 4 using namespace std;
 5
 6
 7 int main(){
 8     int t;
 9   /*  for(int i=0;i<=100;i++){
10         int co=0;
11         for(int j=0;j<=i;j++){
12             if((i-j-(i^j))==0){
13                 co++;
14             }
15         }
16         cout<<i<<" "<<co<<endl;
17     }*/
18
19     cin>>t;
20     int n;
21     while(t--){
22         cin>>n;
23         int num=__builtin_popcount(n);
24         ll ans=pow(2,num);
25         cout<<ans<<endl;
26     }
27 }

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 pb push_back
 7 #define eb emplace_back
 8 #define maxn 300005
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef pair<int,int> pii;
14 typedef pair<long long,int>pli;
15 typedef pair<int,char> pic;
16 typedef pair<pair<int,string>,pii> ppp;
17 typedef unsigned long long ull;
18 const long long mod=1e9+7;
19 using namespace std;
20
21 int n;
22 string str;
23 map<char,int>mp;
24 map<char,int>::iterator it;
25 string ans;
26 vector<char>ve;
27 int main(){
28     cin>>n>>str;
29     for(int i=0;i<n;i++){
30         ve.pb(str[i]);
31     }
32     sort(ve.begin(),ve.end());
33     for(int i=0;i<ve.size();i++) cout<<ve[i];
34
35 }

D

题意:一个人可以上下左右移动,但是左右移动有次数限制,求他活动范围最多是多少个格子

思路:bfs搜索,用book数组标记剩余的左右移动的次数

 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 eb emplace_back
 8 #define maxn 300005
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef pair<int,int> pii;
14 typedef pair<long long,int>pli;
15 typedef pair<int,char> pic;
16 typedef pair<pair<int,string>,pii> ppp;
17 typedef unsigned long long ull;
18 const long long mod=1e9+7;
19 using namespace std;
20
21 int n,m;
22 char str[2005][2005];
23 struct Num{
24     int L,R;
25 }book[2005][2005];
26 int r,c,L,R;
27 struct sair{
28     int x,y,L,R;
29 };
30 int dir[4][2]={0,-1,-1,0,0,1,1,0};//R,D,L,U
31
32 void bfs(){
33     queue<sair>Q;
34     sair s,e;
35     s.x=r,s.y=c,s.L=L,s.R=R;
36     Q.push(s);
37     book[s.x][s.y].L=L;
38     book[s.x][s.y].R=R;
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>=0&&e.x<n&&e.y>=0&&e.y<m&&str[e.x][e.y]!=‘*‘){
46                 e.L=s.L;
47                 e.R=s.R;
48                 if(i==2){
49                     e.R--;
50                     if(e.R<0) continue;
51                 }
52                 else if(i==0){
53                     e.L--;
54                     if(e.L<0) continue;
55                 }
56                 if(book[e.x][e.y].L<e.L||book[e.x][e.y].R<e.R){
57                     book[e.x][e.y].L=max(book[e.x][e.y].L,e.L);
58                     book[e.x][e.y].R=max(book[e.x][e.y].R,e.R);
59                     Q.push(e);
60                 }
61
62             }
63         }
64     }
65 }
66
67 int main(){
68     std::ios::sync_with_stdio(false);
69     cin>>n>>m;
70     cin>>r>>c;
71     cin>>L>>R;
72     for(int i=0;i<=2000;i++){
73         for(int j=0;j<=2000;j++){
74             book[i][j].L=book[i][j].R=-1;
75         }
76     }
77     for(int i=0;i<n;i++){
78         cin>>str[i];
79     }
80     r--,c--;
81     bfs();
82     int ans=0;
83     for(int i=0;i<n;i++){
84         for(int j=0;j<m;j++){
85             if(book[i][j].L!=-1||book[i][j].R!=-1){
86                 ans++;
87             }
88         }
89     }
90     cout<<ans<<endl;
91 }

E

交互题

题意:输出n个点,每输出一个点会告诉你这点是黑色还是白色 ,最后输出一条线段,使黑白色的点分别在线段的两边

思路:二分,当点的颜色与第一个点相同时,往右走,否则往左走,这样就把不同颜色的点分成两边。因为n为30,范围为1e9,所以可以二分30次

 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 eb emplace_back
 8 #define maxn 300005
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef pair<int,int> pii;
14 typedef pair<long long,int>pli;
15 typedef pair<int,char> pic;
16 typedef pair<pair<int,string>,pii> ppp;
17 typedef unsigned long long ull;
18 const long long mod=1e9+7;
19 using namespace std;
20
21
22 int main(){
23     std::ios::sync_with_stdio(false);
24     int n;
25     cin>>n;
26     string str,s;
27     int L=0,R=1e9;
28     int ans=0;
29     cout<<ans<<" "<<1<<endl;
30     cin>>s;
31     for(int i=1;i<n;i++){
32         ans=L+R>>1;
33         cout<<ans<<" "<<1<<endl;
34         cin>>str;
35         if(str==s){
36             L=ans;
37         }
38         else{
39             R=ans;
40         }
41     }
42     cout<<L<<" "<<2<<" "<<R<<" "<<0<<endl;
43 }

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

时间: 2024-10-12 01:38:04

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)的相关文章

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) D. Labyrinth

http://codeforces.com/contest/1064/problem/D 向上/向下加0,向左/右加1, step = 0,1,-- 求的是最少的步数,所以使用bfs. step=k -> step=k+1 1.step=k 使用一次左/右 到达 step=k+1 2.step=k+1 无限使用上下,得到所有 step=k+1 的状态 用dijkstra+堆优化 / spfa 超时. 1 #include <bits/stdc++.h> 2 using namespace

Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) B

题链 Description 给一张方格图,对于上下移动无限制,左右移动数分别不能超过L,R,求能到多少点. Sol 发现 新的y坐标=老坐标-左移操作数+右移操作数 所以我们只需最小化左移操作数即可,最短路. Code #include<bits/stdc++.h> #define N 2007 #define pii pair<int,int> #define fi first #define se second using namespace std; char p[N][N

Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) C

题链 Description 和交互库交互,你给出n个点,交互库指定颜色,求一条直线分割颜色. Sol 分别在x轴,y轴上二分即可. Code #include<bits/stdc++.h> #define Mid (l+r>>1) using namespace std; int n,l,r; char p1[102],p2[102],p3[102]; void work(int x,int pos,int g) { l=500000000; r=1000000000; for

Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) D

题链 Description 解一个线性规划(大雾) Sol 单纯形我们发现我们可以暴力枚举转的圈数,而这个东西可以数论分块优化. Code #include <bits/stdc++.h> #define LL long long using namespace std; LL n,x,k,lb,ub,l,r,ans=-1; int main() { scanf("%lld%lld%lld%lld",&n,&l,&r,&k); x=(r&g

Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) E

题链 Description 给一个排列,要求每个激光打到指定的接受器上,最大化这个数量,你的手段只有在n*n的位置上放平面镜. Sol 我们发现一行要么只放‘/’要么只放‘\’,又发现answer=n||answer=n-1,这可以倒着合并. Description #include<bits/stdc++.h> #define N 1006 using namespace std; int n,a[N],last; char ans[N][N]; signed main () { scan

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) B

1 #include<bits/stdc++.h> 2 3 int n,T,cnt; 4 5 int read() 6 { 7 char ch = getchar(); 8 int num = 0; 9 bool fl = 0; 10 for (; !isdigit(ch); ch=getchar()) 11 if (ch=='-') fl = 1; 12 for (; isdigit(ch); ch=getchar()) 13 num = (num<<1)+(num<<

Codeforces Round #486 (Div. 3) A. Diverse Team

Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Description There are n students in a school class, the rating of the i-th student on Codehorses is ai. You have to form a team consisting of k students

Codeforces Round #379 (Div. 2) Analyses By Team:Red &amp; Black

A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lucky_ji: 水题,模拟统计A和D的数目比较大小输出结果即可 Tags: Implementation B.Anton and Digits Problems: 给定k2个2,k3个3,k5个5及k6个6,可以组成若干个32或256,求所有方案中Sigma的最大值 Analysis: lucky_ji: 同

Codeforces Round #544 (Div. 3) C. Balanced Team [暴力剪枝]

You are a coach at your local university. There are n n students under your supervision, the programming skill of the i i -th student is a i ai . You have to create a team for a new programming competition. As you know, the more students some team ha