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 main()
13 {
14     while (scanf("%d", &n) != EOF)
15         solve();
16     return 0;
17 }

B. Game with string

Solved.

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 #define N 100010
 5 char s[N];
 6
 7 int main()
 8 {
 9     while (scanf("%s", s + 1) != EOF)
10     {
11         stack <char> sta;
12         int cnt = 0;
13         for (int i = 1, len = strlen(s + 1); i <= len; ++i)
14         {
15             if (!sta.empty() && sta.top() == s[i]) sta.pop(), ++cnt;
16             else sta.push(s[i]);
17         }
18         puts(cnt & 1 ? "Yes" : "No");
19     }
20     return 0;
21 }

C. Grid game

Solved.

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 #define N 1010
 5 char s[N];
 6
 7 int main()
 8 {
 9     while (scanf("%s", s + 1) != EOF)
10     {
11         int x = 0, y = 0;
12         for (int i = 1, len = strlen(s + 1); i <= len; ++i)
13         {
14             if (s[i] == ‘1‘)
15             {
16                 printf("%d %d\n", 1, x % 2 ? 3 : 1);
17                 ++x;
18             }
19             else
20             {
21                 printf("%d %d\n", 3, y % 4 + 1);
22                 ++y;
23             }
24         }
25     }
26     return 0;
27 }

D. Game with modulo

Solved.

题意:

交互题

猜数,猜一个$a$

每次询问格式为$(x, y)$

返回结果有两种

$x \;if (x \; mod\; a) >= (y \;mod\; a)$

$y \;if (x \;mod\; a) < (y \;mod\; a) $

思路:

我们考虑 从小到大倍增,去找到$a的一个单调范围$

比如说$1, 2, 4, 8, 16, 32  如果某一次询问中返回了x$

那么说明$a在询问的(x, y)范围中  并且2 \cdot a 不在这个范围内$

因为是从小到大进行倍增

那么我们考虑某一次询问是$(x, 2\cdot x)$

$a在其中$

$如果 a > x, 那么必然有x >= 2 \cdot x -  a$

$如果a = x  那么必然有 x \;mod\;a = 2 \cdot x \;mod\; a$

那么这个区间就具有一个单调性,可以进行二分

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 char op[110];
 5
 6 bool check(int x, int y)
 7 {
 8     printf("? %d %d\n", x, y);
 9     fflush(stdout);
10     scanf("%s", op);
11     return op[0] == ‘y‘;
12 }
13
14 void solve(int l, int r)
15 {
16     int base = 1;
17     for (int i = l; i <= r; i += base, base <<= 1)
18     {
19         printf("? %d %d\n", i, i + base);
20         fflush(stdout);
21         scanf("%s", op);
22         if (op[0] == ‘x‘)
23         {
24             int l = i + 1, r = i + base - 1, res = -1;
25             while (r - l >= 0)
26             {
27                 int mid = (l + r) >> 1;
28                 if (check(i, mid))
29                 {
30                     l = mid + 1;
31                     res = mid;
32                 }
33                 else
34                 {
35                     r = mid - 1;
36                 }
37             }
38             if (res == -1) res = i;
39             printf("! %d\n", res + 1);
40             fflush(stdout);
41             return;
42         }
43     }
44
45 }
46
47 int main()
48 {
49     while (scanf("%s", op) && op[0] != ‘e‘)
50         solve(0, 1000000000);
51     return 0;
52 }

原文地址:https://www.cnblogs.com/Dup4/p/10306995.html

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

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

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 #275 (Div.1) Solution

好久没做题了,开场Virtual热热身. A 构造,我的方法是,取1,2,3...,k这几个差值,前k+1个数分别是 1, k+1, 2, k, ...., 之后就k+2, k+3, ..., n B 因为题设是与操作.我们按照每一位来,如果有一个限制某位是1,则将那段区间标志1,没有限制的位全部置零即可,然后检验为0的位是否全是1.标志一段区间可以用标记法,检验可以求和看差值. C 我做完之后看了CF tutorial 跟我的做法不同.我的做法比他给的复杂度低一点,不过题解好帅,而且跑出来速度

Codeforces Round #282 (Div.1) Solution

上午考试,下去去参观教堂,回来睡大觉,搞到现在才有时间做,水平恢复中. A 倒过来扫括号匹配很容易理解 B dp[i]表示最后一个拿到i的数目,sum[i]表示前i项dp和,sum2[i]表示前i项sum和.显然.dp[i]=sum2[o], o是最右边的坐标使得s[o+1,i]能包含t. C Interesting,我建了个树,硬着dp搞得..还没优化就46ms,想来这种题数据也不好构造. D Editorial似乎说离线搞,不过我在线搞出来了.我存了每个节点子树平方和,子树和,整体和,整体平

[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. 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次

[比赛] Codeforces Round #538 (Div. 2) solution (贪心,数学其他,二分,线段树)

已经写了100篇题解啦! link solution pdf #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; inline int read(){ int f=1,ans=0;char c; while(c<'0'||c>'9'){if(c=='-')f=-1;c

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

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

Codeforces Round #607 (Div. 1) Solution

从这里开始 比赛目录 我又不太会 div 1 A? 我菜爆了... Problem A Cut and Paste 暴力模拟一下. Code #include <bits/stdc++.h> using namespace std; typedef bool boolean; const int N = 1e6 + 5; const int Mod = 1e9 + 7; int T; int x; int len; char s[N]; int paste(int s1, int t1, in

Codeforces Round #268 (Div. 1) solution

A.24 Game 题意:给你1, 2, ..., n-1, n 这个序列,每次你可以取出两个数做+/-/*三种操作之一,然后把结果放回到序列中,询问能否是的这个序列最后只剩下一个24. 解法:首先很明显n < 4的时候是无解的.如果n=4,那么1 * 2 * 3 * 4=24,如果n=5,那么(5 - 1 - 2) * 3 * 4 = 24.若n > 5,那么我可以做n - (n - 1) = 1,相当于变成了n-2时候的情况加一个1,那么显然最后让答案乘上这个1即可. 代码: includ