Codeforces Round #534 (Div. 2)

A. Splitting into digits

题意:把一个数分成若干[1,9]之间的数字,使得这些数尽量相同。

思路:输出n个1。

#include<bits/stdc++.h>
#define CLR(a,b) memset(a,,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=100010;
int main(){
    int n;
    cin>>n;
    int flag=0,j=2;
    printf("%d\n",n);
    for(int i=1;i<=n;i++)
    {
        printf("%d",1);
        if(i==n)puts("");
        else printf(" ");
    }
}

B. Game with string

题意,给出一个字符串,两个人轮流玩游戏,每次可以把相邻且相同的两个字母删除,然后把剩下的字符串拼起来,两个人轮流操作,不能操作就输了,问第一个人能不能赢。

思路:和括号序列很像,用一个栈来维护字符串,每次都和栈顶元素比较一下,相同就删去,不同就入栈。

#include<bits/stdc++.h>
#define CLR(a,b) memset(a,,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=100010;
char s[maxn];
stack<char>ss;
int main() {
    int n;
    while(cin>>s) {
        while(!ss.empty())ss.pop();
        n=strlen(s);
        int ans=0;
        int pos=0;
        for(int i=0; i<=n-1; i++) {
            if(ss.empty()) {
                ss.push(s[i]);
                continue;
            }
            char c=ss.top();
            if(c==s[i]) {
                ans++;
                ss.pop();
            } else {
                ss.push(s[i]);
            }
        }

        if(ans%2==1) {
            printf("Yes\n");
        } else puts("No");
    }
}

C. Grid game

题意,在4*4的网格中放1*2  和2*1的小矩形,同一行或者同一列被占满则被消除,要你构造一个方案,使网格不会被占满(溢出)。

思路:抛开下面的样例描述就很简单了,2*1的每次都放在一列,两个就能消除,就不会占满,2*1的每四个都摞起来,这样也不会占满。

#include<bits/stdc++.h>
#define CLR(a,b) memset(a,,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=100010;
char s[maxn];
stack<char>ss;
int main() {
    int n;
    while(scanf("%s",s)!=EOF) {
        int a=0,b=0;
        for(int i=0;i<strlen(s);i++)
        {
            if(s[i]==‘0‘){
                if(a==0){
                    printf("1 1\n");
                    a++;
                }else{
                    printf("3 1\n");
                    a=0;
                }
            }else{
                    b=b%4+1;

                    printf("%d 3\n",b);

            }
        }
    }
}

D. Game with modulo

题意:交互题,系统会生成一个数a,然后你需要给出(x,y)这样的一个二元组,当x%a >= y %a 时,系统返回“x”,否则返回“y”,你需要在60次询问内,判断a这个数字并且输出。

倍增加二分,第一次做交互题。

如果你给出数是x<y的,当a大于x和y时,系统返回的必定是y,只有当x<a<y时,系统才会返回x。

所以一开始x从0开始,y从1开始,每次以2的幂次递增,然后就可以得到一个大的区间范围,然后用同样的方法进行二分。

#include<bits/stdc++.h>
#define CLR(a,b) memset(a,,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=100010;
string opers,replay;
ll x,y;
int main(){
    cin>>opers;
    while(opers!="end"&&opers!="mistake")
    {
        x=0,y=1;
        replay="y";
        while(replay=="y")
        {
            printf("? %lld %lld\n",x,y);
            cin>>replay;
            if(replay=="y"){
                x=y;
                y=y*2;
            }
        }
        ll l=x,r=y,mid;
        while(l<r-1)
        {
            mid=(l+r)>>1;
            printf("? %lld %lld\n",x,mid);
            cin>>replay;
            if(replay=="y"){
                l=mid;
            }else{
                r=mid;
            }
        //    printf("l:%lld  r:%lld\n",l,r);
        }
        printf("! %lld\n",l+1);
        cin>>opers;
    }
    if(opers=="mistake")return 0;
} 

E. Johnny Solving

待补。

原文地址:https://www.cnblogs.com/mountaink/p/10308640.html

时间: 2024-08-30 06:15:28

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

Codeforces Round #534 (Div. 2)题解

Codeforces Round #534 (Div. 2)题解 A. Splitting into digits 题目大意 将一个数字分成几部分,几部分求和既是原数,问如何分可以使得分出来的各个数之间的差值尽可能小 解题思路 将n分成n个1相加即可 AC代码 #include<cstring> #include<string> #include<iostream> #include<cstdio> using namespace std; int main

Codeforces Round #534 (Div. 2) D. Game with modulo(取余性质+二分)

D. Game with modulo 题目链接:https://codeforces.com/contest/1104/problem/D 题意: 这题是一个交互题,首先一开始会有一个数a,你最终的目的是要将它猜出来. 每次询问会输出"? x y",然后有: "x" (without quotes), if (x % a)≥(y % a). "y" (without quotes), if (x % a)<(y % a). 最多给你60次

CF1103C Johnny Solving (Codeforces Round #534 (Div. 1)) 思维+构造

题目传送门 https://codeforces.com/contest/1103/problem/C 题解 这个题还算一个有难度的不错的题目吧. 题目给出了两种回答方式: 找出一条长度 \(\geq \frac nk\) 的路径: 找出 \(k\) 个简单环,满足长度不是 \(3\) 的倍数,并且每个环至少存在一个点不在别的环中. 很显然题目并不是要你随便挑一种回答方式开始单独研究.最有可能的情况是两种回答方式可以替补. 如果我们随便作出原图的一棵生成树,如果最长的路径长度 \(\geq \f

Codeforces Round #534 (Div. 2) Solution

A. Splitting into digits Solved. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int n; 5 6 void solve() 7 { 8 printf("%d\n", n); 9 for (int i = 1; i <= n; ++i) printf("%d%c", 1, " \n"[i == n]); 10 } 11 12 int

[ACM]Codeforces Round #534 (Div. 2)

一.前言 二.题面 A. Splitting into digits Vasya has his favourite number n. He wants to split it to some non-zero digits. It means, that he wants to choose some digits d1,d2,-,dk, such that 1≤di≤9 for all i and d1+d2+-+dk=n. Vasya likes beauty in everything

Codeforces Round #534 (Div. 1)

A 构造题 有一个44的方格 每次放入一个横向12或竖向2*1的方格 满了一行或一列就会消掉 求方案 不放最后一行 这样竖行就不会消 然后竖着的放前两行 横着的放第三行 循环放就可以啦 #include <cstdlib> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> const int N = 1e3 + 5; using namespace

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我