zoukankan      html  css  js  c++  java
  • 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 }
    View Code

    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 }
    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 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 }
    View Code

    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 }
    View Code

    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 }
    View Code
  • 相关阅读:
    Java实现 蓝桥杯VIP 算法训练 数的统计
    Java实现 蓝桥杯VIP 算法训练 和为T
    Java实现 蓝桥杯VIP 算法训练 友好数
    Java实现 蓝桥杯VIP 算法训练 连续正整数的和
    Java实现 蓝桥杯VIP 算法训练 寂寞的数
    Java实现 蓝桥杯VIP 算法训练 学做菜
    Java实现 蓝桥杯VIP 算法训练 暗恋
    Java实现 蓝桥杯VIP 算法训练 暗恋
    测试鼠标是否在窗口内,以及测试鼠标是否在窗口停留
    RichEdit 各个版本介绍
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/10559264.html
Copyright © 2011-2022 走看看