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

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

  • Solved : 3 out of 6
  • Rank : 1347
  • A. Make a triangle!
  • 难度: 普及?
  • 数学题。。。若刚好能凑成三角形就输出0,否则,设a,b,c从大到小排序,则\(a+x+b>c ~-> ~a+x+b\leq c+1 ~->~ x=c-b-a+1\),其中x是最小增加次数。
 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<utility>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
int read(){
    int x=0,f=1;char ch=' ';
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^'0');ch=getchar();}
    return x*f;
}
int main() {
    int a, b, c;scanf("%d%d%d", &a,&b,&c);
    int ans;
    int C=max(a,max(b,c)),A=min(a,min(b,c)),B;
    if(C==c){
        if(A==a) B=b;
        else if(A==b) B=a;
    }
    else if(C==b){
        if(A==a) B=c;
        else if(A==c) B=a;
    }
    else if(C==a){
        if(A==b) B=c;
        else if(A==c) B=b;
    }//我承认上面写的很zz。。。
//  printf("a=%d b=%d c=%d\n",A,B,C);
    if(A+B>C) ans=0;
    else {
        ans=C-B-A+1;
    }
    printf("%d",ans);
    return 0;
}
  • B. Equations of Mathematical Magic
  • 难度:普及?
    • $a- (a \oplus b)-b= 0 ~->~ a \oplus b = a-b $
    • 然后想到a中所有1的位xor b中1的位后是0,a中1的位减b中1的位也是0,得出一个猜想:ans为a的二进制下1的位数,然后用计算器看到大样例有30个1,而答案恰好为30。
    • 直接得出结论。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<utility>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
int read(){
    int x=0,f=1;char ch=' ';
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^'0');ch=getchar();}
    return x*f;
}
int main() {
    int t;t=read();
    while(t--){
        int a;a=read();
        int cnt=0;
        for(;a;a>>=1){
            if(a&1) cnt++;
        }
        long long ans=(1<<cnt);
        printf("%I64d\n",ans);
    }
    return 0;
}
  • C. Oh Those Palindromes
    • 难度:普及?
    • 本以为是个有点难度的构造题,结果把字符串排个序就完了。。。。。(被旁边的dalao疯狂嘲讽
    • 乱搞一下样例可得出结论。(请不要问我证明。。。
    • Summary :
    • 先手玩一下样例,看能不能找到可以贪心或乱搞的地方。
    • 若有猜想,先跑一下样例看看能不能过,如果大样例都过了的话。。。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<utility>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
int read(){
    int x=0,f=1;char ch=' ';
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^'0');ch=getchar();}
    return x*f;
}
const int N = 100000 +100;
char s[N];
int main() {
    int n; n =read();
    scanf("%s",s+1);
    sort(s+1,s+n+1);
    printf("%s",s+1);
    return 0;
}
  • D. Labyrinth
  • 难度:提高D1T2?
  • 双端队列BFS。
  • 向上和向下移动的代价都为0,向左或向右的代价为1。我们将花费代价为0的状态从队头入队,花费代价为1的状态从队尾入队。当一个状态第一次从队列中取出时,就得到了此状态的最优解。当然本题是要跑出所有可能的解而非求最优解。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N = 2000 + 100;
int n,m;
char mp[N][N];
struct node{
    int x,y,l,r;
};
bool vis[N][N];
deque<node>q;
const int dirx[4]={-1,1,0,0};
const int diry[4]={0,0,-1,1};
void BFS(){
    while(q.size()) {
        node _=q.front();q.pop_front();
        int x=_.x,y=_.y,l=_.l,r=_.r;
        if(l<0||r<0) continue;
        if(vis[x][y]) continue;
        vis[x][y]=1;
        for(int i=0;i<4;i++){
            int xx=x+dirx[i],yy=y+diry[i],ll=l,rr=r;
            if(xx<1||xx>n||yy<1||yy>m||mp[xx][yy]=='*') continue;
            if(i==2) ll--;
            if(i==3) rr--;
            if(i==0||i==1) q.push_front((node){xx,yy,ll,rr});
            if(i==2||i==3) q.push_back((node){xx,yy,ll,rr});
        }
    }
}
int main() {
    int R,C;
    scanf("%d%d%d%d",&n,&m,&R,&C);
    int X,Y;scanf("%d%d",&X,&Y);
    for(int i=1;i<=n;i++) {
        scanf("%s",mp[i]+1);
    }
    node _=(node){R,C,X,Y};
    q.push_front(_);
    BFS();
    int ans=0;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++){
            if(vis[i][j]) ans++;
        }
    }
    printf("%d",ans);
    return 0;
}
  • E. Dwarves, Hats and Extrasensory Abilities
  • 难度:提高D2T2?交互题不清楚
  • F. Candies for Children
  • 难度: 省选?
  • 神仙题。

转载于:https://www.cnblogs.com/Loi-Brilliant/p/9826916.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值