Codeforces Round #640 (Div. 4) 小结①下

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




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值