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。

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

代码:

 #include <bits/stdc++.h>
#define MAXN 100005 char ch[MAXN];
int len, tot; struct node {
char s;
int l, r;
} a[MAXN];
.
int chk(int o) {
int l = o, r = o + ; tot++;
while (a[a[l].l].s == a[a[r].r].s && a[a[l].l].s != '\000')
l = a[l].l, r = a[r].r, tot++;
a[a[r].r].l = a[l].l;
return a[r].r;
} int main() {
scanf("%s", ch + ), len = strlen(ch + );
for (int i = ; i <= len; i++) a[i].s = ch[i], a[i].l = i - , a[i].r = i + ;
for (int i = ; i <= len; i = (a[i].s == a[i + ].s && a[i].s != '\000') ? chk(i) : i + );
printf(tot % ? "Yes" : "No");
return ;
}

C. Grid game

You are given a 4x4 grid. You play a game — there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in the grid. When tile is placed, each cell which is located in fully occupied row or column is deleted (cells are deleted at the same time independently). You can place tile in the grid at any position, the only condition is that tiles (and tile parts) should not overlap. Your goal is to proceed all given figures and avoid crossing at any time.

Input
The only line contains a string s consisting of zeroes and ones (1≤|s|≤1000). Zero describes vertical tile, one describes horizontal tile.

Output
Output |s| lines — for each tile you should output two positive integers r,c, not exceeding 4, representing numbers of smallest row and column intersecting with it.

If there exist multiple solutions, print any of them.

Example
input
010
output
1 1
1 2
1 4

[ACM]Codeforces Round #534 (Div. 2)的更多相关文章

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

    D. Game with modulo 题目链接:https://codeforces.com/contest/1104/problem/D 题意: 这题是一个交互题,首先一开始会有一个数a,你最终的 ...

  2. CF1103D Codeforces Round #534 (Div. 1) Professional layer 状压 DP

    题目传送门 https://codeforces.com/contest/1103/problem/D 题解 失去信仰的低水平选手的看题解的心路历程. 一开始看题目以为是选出一些数,每个数可以除掉一个 ...

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

    题目传送门 https://codeforces.com/contest/1103/problem/C 题解 这个题还算一个有难度的不错的题目吧. 题目给出了两种回答方式: 找出一条长度 \(\geq ...

  4. Codeforces Round #534 (Div. 1)

    A 构造题 有一个44的方格 每次放入一个横向12或竖向2*1的方格 满了一行或一列就会消掉 求方案 不放最后一行 这样竖行就不会消 然后竖着的放前两行 横着的放第三行 循环放就可以啦 #includ ...

  5. Codeforces Round #534 (Div. 2)D. Game with modulo-1104-D(交互+二分+构造)

    D. Game with modulo time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #534 (Div. 2)

    B. Game with string 题意: 给出一个字符串s只包括小写字母.当轮到一个玩家的时候,他可以选择两个连续且相等的字母并且删除它.当一个玩家没得删的时候他就输了. 题解: 乍一看有点懵, ...

  7. Codeforces Round #534 (Div. 2) Solution

    A. Splitting into digits Solved. #include <bits/stdc++.h> using namespace std; int n; void sol ...

  8. Codeforces 1104 D. Game with modulo-交互题-二分-woshizhizhang(Codeforces Round #534 (Div. 2))

    D. Game with modulo time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #534 (Div. 2) D. Game with modulo 交互题

    先二分一个区间,再在区间里面二分即可: 可以仔细想想,想明白很有意思的: #include<iostream> #include<cstdio> #include<alg ...

随机推荐

  1. 第六章P2P技术及应用

    第六章P2P技术及应用 P2P技术在我们日常生活中非常实用,例如我们常用的QQ.PPLive.BitTorrent就是基于P2P技术研发.下面将本章中的重点内容进行归纳. 文章中的Why表示产生的背景 ...

  2. 网络安全攻防----html基础

    一.学习html的硬件条件 网页(.Html)是静态的,学习html语言需要选择Chrome浏览器和Sublime3编辑器,选择Chrome浏览器是因为Chrome浏览器兼容性比较好,支持各种各样的插 ...

  3. 20135208 JAVA第四次实验

    课程:Java程序与设计     班级:1352 姓名:贺邦 小组成员: 20135212池彬宁 20135208贺邦 学号:20135208 成绩:             指导教师:娄嘉鹏     ...

  4. lintcode-422-最后一个单词的长度

    422-最后一个单词的长度 给定一个字符串, 包含大小写字母.空格' ',请返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 注意事项 一个单词的界定是,由字母组成,但不包含任何的空 ...

  5. 第5章 首次登录与在线求助man page

    首次登录系统 centos默认图像界面为GNOME. Linux默认情况下会提供6个Terminal来让用户登录,切换方式为ctrl+alt+[F1-F6],系统将这六个操作界面命名为tty1-tty ...

  6. 技嘉主板+AMD CPU开启CPU虚拟化方法

    硬件环境:技嘉AB350+AMD Ryzen 5 1600X 由于安装虚拟机的需要,所以要开启CPU的虚拟化. 首先进入BIOS. 然后如图:(M.I.T-高级频率设定-CPU超频进阶设置-SVM M ...

  7. cobbler-web 网络安装服务器套件 Cobbler(补鞋匠)

    Cobbler作为一个预备工具,使部署RedHat/Centos/Fedora系统更容易,同时也支持Suse和Debian系统的部署. 它提供以下服务集成:   * PXE服务支持 * DHCP服务管 ...

  8. 【leetcode】59.Spiral Matrix II

    Leetcode59 Spiral Matrix II Given an integer n, generate a square matrix filled with elements from 1 ...

  9. 找xpath好用的工具(比较少用,针对只能在IE上打开的网站)

    有一些网站只能在IE浏览器里打开,不像firefox那样有好多好用的插件来找元素的xpath,css path等. 当然现在IE也可以,F12出现像firebug那样的窗口,来查看元素. 这里呢在介绍 ...

  10. elementUI使用本地变量进行验证,监测不到本地变量的变化 的问题

    对于饿了么组件自定义验证规则,组件库文档已经非常详细了:http://element-cn.eleme.io/#/zh-CN/component/form 我这里将验证中固定的值提取出来使用变量进行保 ...