A
Sum of Round Numbers
A positive (strictly greater than zero) integer is called round if it is of the form d00…0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1≤n≤104). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1≤t≤104) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1≤n≤104).
Output
Print t answers to the test cases. Each answer must begin with an integer k — the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
input
5
5009
7
9876
10000
10
output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10
题意:就是一串数,如果位数大于1,那个数必须后边都是0,如果不是你就得拆开,然后输出拆分后的结果 ,例如5009—5000 9;
感觉写麻烦了、、、
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
using namespace std;
#define inf 0x3f3f3f3f3f;
typedef long long ll;
int a[100];
int main()
{
int t; cin >> t;
while (t--)
{
string s; cin >> s;
int l = s.size();
int u = 1;
for (int i =1; i < l; i++)
{
if (s[i] != '0')
{
u++;
}
}
if (u ==1)
{
cout << 1 << endl << s << endl;
}
else
{
cout << u << endl;
for (int i =0; i<l;i++)
{
if (s[i] != '0')
{
cout << s[i];
int o = i;
while (o < l-1)
{
cout << "0";
o++;
}
cout << " ";
}
}
}
cout << endl;
}
}
B
Same Parity Summands
You are given two positive integers n (1≤n≤109) and k (1≤k≤100). Represent the number n as the sum of k positive integers of the same parity (have the same remainder when divided by 2).
In other words, find a1,a2,…,ak such that all ai>0, n=a1+a2+…+ak and either all ai are even or all ai are odd at the same time.
If such a representation does not exist, then report it.
Input
The first line contains an integer t (1≤t≤1000) — the number of test cases in the input. Next, t test cases are given, one per line.
Each test case is two positive integers n (1≤n≤109) and k (1≤k≤100).
Output
For each test case print:
YES and the required values ai, if the answer exists (if there are several answers, print any of them);
NO if the answer does not exist.
The letters in the words YES and NO can be printed in any case.
Example
input
8
10 3
100 4
8 7
97 2
8 8
3 10
5 3
1000000000 9
output
YES
4 2 4
YES
55 5 5 35
NO
NO
YES
1 1 1 1 1 1 1 1
NO
YES
3 1 1
YES
111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111120
题意:给n,k,n表示一些整数和,k表示整数的个数。这k个整数,必须都为偶数或者都为奇数才可以哦,如果能的话输出yes和结果
思路:这题当时自己看了下,首先样例输出的结果没啥规律,觉着挺头疼的,就没深入思考,但是其实我想过 都输出 1或者 2这种方法的,但自己没坚持下去。其实这个题就是这样做。不是总共k个数么,我可以看 n-(k-1) n-(k-1)*2这两个数的结果,来输出
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
using namespace std;
#define inf 0x3f3f3f3f3f;
typedef long long ll;
int main()
{
int t; cin >> t;
while (t--)
{
int n, k; cin >> n >> k;
int a1 = n - (k - 1); int a2 = n - (k - 1) * 2;
if (a1 > 0 && a1 % 2 != 0)
{
cout << "YES" << endl;
for (int i = 1; i <= k - 1; i++)
cout << "1";
cout << a1 << endl;
continue;
}
if (a2 > 0 && a2 % 2 == 0)
{
cout << "YES" << endl;
for (int i = 1; i <= k - 1; i++)
cout << "2";
cout << a2 << endl;
continue;
}
cout << "NO" << endl;
}
}
C. K-th Not Divisible by n
You are given two positive integers n and k. Print the k-th positive integer that is not divisible by n.
For example, if n=3, and k=7, then all numbers that are not divisible by 3 are: 1,2,4,5,7,8,10,11,13…. The 7-th number among them is 10.
Input
The first line contains an integer t (1≤t≤1000) — the number of test cases in the input. Next, t test cases are given, one per line.
Each test case is two positive integers n (2≤n≤109) and k (1≤k≤109).
Output
For each test case print the k-th positive integer that is not divisible by n.
Example
input
6
3 7
4 12
2 1000000000
7 97
1000000000 1000000000
2 1
output
10
15
1999999999
113
1000000001
1
题意:给你n,k,求第k个不能整除n的数是多少
思路:这种题自己总是想不到去找找规律,跟个傻子一样!它能整除的就那几个点吧,你直接在后头加上这些能整除的点的个数,能整除n的数之间有 n-1个不能整除n的数,
int t; cin >> t;
while (t--)
{
int n, k; cin >> n >> k;
if (k%(n-1)==0)//最后一个是能整除n的数
{
cout << (k + k / (n - 1)) - 1 << endl;
}
else
{
cout << k + k / (n - 1) << endl;
}
}
D Alice, Bob and Candies
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
There are n candies in a row, they are numbered from left to right from 1 to n. The size of the i-th candy is ai.
Alice and Bob play an interesting and tasty game: they eat candy. Alice will eat candy from left to right, and Bob — from right to left. The game ends if all the candies are eaten.
The process consists of moves. During a move, the player eats one or more sweets from her/his side (Alice eats from the left, Bob — from the right).
Alice makes the first move. During the first move, she will eat 1 candy (its size is a1). Then, each successive move the players alternate — that is, Bob makes the second move, then Alice, then again Bob and so on.
On each move, a player counts the total size of candies eaten during the current move. Once this number becomes strictly greater than the total size of candies eaten by the other player on their previous move, the current player stops eating and the move ends. In other words, on a move, a player eats the smallest possible number of candies such that the sum of the sizes of candies eaten on this move is strictly greater than the sum of the sizes of candies that the other player ate on the previous move. If there are not enough candies to make a move this way, then the player eats up all the remaining candies and the game ends.
For example, if n=11 and a=[3,1,4,1,5,9,2,6,5,3,5], then:
move 1: Alice eats one candy of size 3 and the sequence of candies becomes [1,4,1,5,9,2,6,5,3,5].
move 2: Alice ate 3 on the previous move, which means Bob must eat 4 or more. Bob eats one candy of size 5 and the sequence of candies becomes [1,4,1,5,9,2,6,5,3].
move 3: Bob ate 5 on the previous move, which means Alice must eat 6 or more. Alice eats three candies with the total size of 1+4+1=6 and the sequence of candies becomes [5,9,2,6,5,3].
move 4: Alice ate 6 on the previous move, which means Bob must eat 7 or more. Bob eats two candies with the total size of 3+5=8 and the sequence of candies becomes [5,9,2,6].
move 5: Bob ate 8 on the previous move, which means Alice must eat 9 or more. Alice eats two candies with the total size of 5+9=14 and the sequence of candies becomes [2,6].
move 6 (the last): Alice ate 14 on the previous move, which means Bob must eat 15 or more. It is impossible, so Bob eats the two remaining candies and the game ends.
Print the number of moves in the game and two numbers:
a — the total size of all sweets eaten by Alice during the game;
b — the total size of all sweets eaten by Bob during the game.
Input
The first line contains an integer t (1≤t≤5000) — the number of test cases in the input. The following are descriptions of the t test cases.
Each test case consists of two lines. The first line contains an integer n (1≤n≤1000) — the number of candies. The second line contains a sequence of integers a1,a2,…,an (1≤ai≤1000) — the sizes of candies in the order they are arranged from left to right.
It is guaranteed that the sum of the values of n for all sets of input data in a test does not exceed 2⋅105.
Output
For each set of input data print three integers — the number of moves in the game and the required values a and b.
Example
input
7
11
3 1 4 1 5 9 2 6 5 3 5
1
1000
3
1 1 1
13
1 2 3 4 5 6 7 8 9 10 11 12 13
2
2 1
6
1 1 1 1 1 1
7
1 1 1 1 1 1 1
output
6 23 21
1 1000 0
2 1 2
6 45 46
2 2 1
3 4 2
4 4 3
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
using namespace std;
#define inf 0x3f3f3f3f3f;
typedef long long ll;
int c[10001];
int main()
{
int t; cin >> t;
while (t--)
{
int n; cin >> n;
for (int i =0; i <n; i++)
cin >> c[i];
n--;
int a = 0, b = 0, sum = 0, s = 0; int u = 0;
for (int i = 0; i <=n;)
{
s++;
sum = c[i];
i++;
while (sum <= u && i <= n)
{
sum += c[i]; i++;
}
a += sum;
u = sum;
if (i > n)break;
s++;
sum = c[n]; n--;
while (sum <= u && i <= n)
{
sum += c[n]; n--;
}
b += sum;
u = sum;
}
cout << s <<" "<< a << " " << b << endl;
}
}