[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, so he wants to find any solution with the minimal possible number of different digits among d1,d2,…,dk. Help him!

Input
The first line contains a single integer n — the number that Vasya wants to split (1≤n≤1000).

Output
In the first line print one integer k — the number of digits in the partition. Note that k must satisfy the inequality 1≤k≤n. In the next line print k digits d1,d2,…,dk separated by spaces. All digits must satisfy the inequalities 1≤di≤9.

You should find a partition of n in which the number of different digits among d1,d2,…,dk will be minimal possible among all partitions of n into non-zero digits. Among such partitions, it is allowed to find any. It is guaranteed that there exists at least one partition of the number n into digits.

Examples
input
1
output
1
1

input
4
output
2
2 2

input
27
output
3
9 9 9

Note
In the first test, the number 1 can be divided into 1 digit equal to 1.

In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1,1,1,1], [2,2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1,1,2] isn‘t an answer, because it has 2 different digits, that isn‘t the minimum possible number.

题意:尝试用k个数字(0~9)加起来变成n,要求数字种类尽可能少,即能全部用相同的数字时就不用不同的数字。

正解:cf日常无聊题。第一行输出n,第二行输出n个1即可。

代码:略

B. Game with string

Two people are playing a game with a string s, consisting of lowercase latin letters.

On a player‘s turn, he should choose two consecutive equal letters in the string and delete them.

For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses.

Your task is to determine which player will win if both play optimally.

Input
The only line contains the string s, consisting of lowercase latin letters (1≤|s|≤100000), where |s| means the length of a string s.

Output
If the first player wins, print "Yes". If the second player wins, print "No".

Examples
input
abacaba

output
No

input
iiq

output
Yes

input
abba

output
No

Note
In the first example the first player is unable to make a turn, so he loses.

In the second example first player turns the string into "q", then second player is unable to move, so he loses.

题意:每次从给出的字符串删去两个相连且相同的字符,删去个数为奇数时输出Yes,偶数输出No。

思路:扫描字符串,找到相连的相同字符后,左端点向左,右端点向右进行搜索,直至左右端点不是相同字符,结束,继续扫描,直至字符串末尾。注意,删除子串后应将删除部分的左端和右端相连,以保证后面的扫描的正确性。解决这个问题,我们可以先对字符串进行链标记,对字符进行串联,即对每一个字符标记一个左字符和右字符,初始即其左右的临近字符,在每次操作后可将该标记进行调整。

代码:

 1 #include <bits/stdc++.h>
 2 #define MAXN 100005
 3
 4 char ch[MAXN];
 5 int len, tot;
 6
 7 struct node {
 8     char s;
 9     int l, r;
10 } a[MAXN];
11 .
12 int chk(int o) {
13     int l = o, r = o + 1; tot++;
14     while (a[a[l].l].s == a[a[r].r].s && a[a[l].l].s != ‘\000‘)
15         l = a[l].l, r = a[r].r, tot++;
16     a[a[r].r].l = a[l].l;
17     return a[r].r;
18 }
19
20 int main() {
21     scanf("%s", ch + 1), len = strlen(ch + 1);
22     for (int i = 1; i <= len; i++) a[i].s = ch[i], a[i].l = i - 1, a[i].r = i + 1;
23     for (int i = 1; i <= len; i = (a[i].s == a[i + 1].s && a[i].s != ‘\000‘) ? chk(i) : i + 1);
24     printf(tot % 2 ? "Yes" : "No");
25     return 0;
26 }

原文地址:https://www.cnblogs.com/jinkun113/p/10312058.html

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

[ACM]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

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; prin

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 #261 (Div. 2)[ABCDE]

Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden 题意: 一个正方形,它的边平行于坐标轴,给出这个正方形的两个点,求出另外两个点. 分析: 推断下是否平行X轴或平行Y轴,各种if. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: A.cpp * Create Date: 2014-0

Codeforces Round #264 (Div. 2)[ABCDE]

Codeforces Round #264 (Div. 2)[ABCDE] ACM 题目地址: Codeforces Round #264 (Div. 2) 这场只出了两题TAT,C由于cin给fst了,D想到正解快敲完了却game over了... 掉rating掉的厉害QvQ... A - Caisa and Sugar[模拟] 题意: Caisa拿s美元去超市买sugar,有n种sugar,每种为xi美元yi美分,超市找钱时不会找美分,而是用sweet代替,当然能用美元找就尽量用美元找.他

Codeforces Round #258 (Div. 2)[ABCD]

Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意: Akshat and Malvika两人玩一个游戏,横竖n,m根木棒排成#型,每次取走一个交点,交点相关的横竖两条木棒要去掉,Akshat先手,给出n,m问谁赢. 分析: 水题,很明显不管拿掉哪个点剩下的都是(n-1,m-1),最后状态是(0,x)或(x,0),也就是拿了min(n,m)-1次,