A. Splitting into digits
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya has his favourite number nn. He wants to split it to some non-zero digits. It means, that he wants to choose some digits d1,d2,…,dkd1,d2,…,dk, such that 1≤di≤91≤di≤9 for all ii and d1+d2+…+dk=nd1+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,…,dkd1,d2,…,dk. Help him!
Input
The first line contains a single integer nn — the number that Vasya wants to split (1≤n≤10001≤n≤1000).
Output
In the first line print one integer kk — the number of digits in the partition. Note that kk must satisfy the inequality 1≤k≤n1≤k≤n. In the next line print kk digits d1,d2,…,dkd1,d2,…,dk separated by spaces. All digits must satisfy the inequalities 1≤di≤91≤di≤9.
You should find a partition of nn in which the number of different digits among d1,d2,…,dkd1,d2,…,dk will be minimal possible among all partitions of nn 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 nn into digits.
Examples
input
Copy
1
output
Copy
1 1
input
Copy
4
output
Copy
2 2 2
input
Copy
27
output
Copy
3 9 9 9
Note
In the first test, the number 11 can be divided into 11 digit equal to 11.
In the second test, there are 33 partitions of the number 44 into digits in which the number of different digits is 11. This partitions are [1,1,1,1][1,1,1,1], [2,2][2,2] and [4][4]. Any of these partitions can be found. And, for example, dividing the number 44 to the digits [1,1,2][1,1,2] isn't an answer, because it has 22 different digits, that isn't the minimum possible number.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int n;
cin>>n;
for(int i=1;i<=9;i++)
{
if(n%i==0)
{
printf("%d\n",n/i);
for(int j=1;j<=n/i;j++) printf("%d ",i);
break;
}
}
}
B. Game with string
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Two people are playing a game with a string ss, 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 ss, consisting of lowercase latin letters (1≤|s|≤1000001≤|s|≤100000), where |s||s| means the length of a string ss.
Output
If the first player wins, print "Yes". If the second player wins, print "No".
Examples
input
Copy
abacaba
output
Copy
No
input
Copy
iiq
output
Copy
Yes
input
Copy
abba
output
Copy
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.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int main()
{
cin>>s;
int ans=0;
for(int i=1;s[i];i++)
{
if(s[i-1]==s[i])
{
ans++;
s.erase(s.begin()+i-1);
s.erase(s.begin()+i-1);
if(i-2>=-1) i-=2;
}
}
if(ans%2==0) printf("No");
else printf("Yes");
}
C. Grid game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 ss consisting of zeroes and ones (1≤|s|≤10001≤|s|≤1000). Zero describes vertical tile, one describes horizontal tile.
Output
Output |s||s| lines — for each tile you should output two positive integers r,cr,c, not exceeding 44, representing numbers of smallest row and column intersecting with it.
If there exist multiple solutions, print any of them.
Example
input
Copy
010
output
Copy
1 1 1 2 1 4
Note
Following image illustrates the example after placing all three tiles:
Then the first row is deleted:
这题不会写,看别人博客写的
#include<bits/stdc++.h>
using namespace std;
int main()
{
int f1=0,f2=0;
string s;
cin>>s;
for(int i=0;i<s.length();i++)
{
if(s[i]=='0')
{
f1=(f1+1)%5;
if(f1==0) f1++;
printf("4 %d\n",f1+1);
}
else
{
if(f2==0)
{
printf("1 1\n");
f2=1;
}
else
{
printf("1 3\n");
f2=0;
}
}
}
}