昨晚又打了一场div3,只ac了两题,而且a题出题速度太慢了,因为不相信就一直在补a题导致后面都没时间了,等我去做b只用了三分钟就ac了,等我回头再做a比赛就剩十分钟了才过,这也让我知道有的时候一个题花费了太多时间先放过去,不能打乱整个做题的节奏,连续好几次cf只过两题了,等我ac3个题的时候我一定要开瓶可乐庆祝庆祝
言归正转a题
A. Candies
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Recently Vova found nn candy wrappers. He remembers that he bought xx candies during the first day, 2x2x candies during the second day, 4x4x candies during the third day, ……, 2k−1x2k−1x candies during the kk-th day. But there is an issue: Vova remembers neither xx nor kk but he is sure that xx and kk are positive integers and k>1k>1.
Vova will be satisfied if you tell him any positive integer xx so there is an integer k>1k>1 that x+2x+4x+⋯+2k−1x=nx+2x+4x+⋯+2k−1x=n. It is guaranteed that at least one solution exists. Note that k>1k>1.
You have to answer tt independent test cases.
Input
The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases. Then tt test cases follow.
The only line of the test case contains one integer nn (3≤n≤1093≤n≤109) — the number of candy wrappers Vova found. It is guaranteed that there is some positive integer xx and integer k>1k>1 that x+2x+4x+⋯+2k−1x=nx+2x+4x+⋯+2k−1x=n.
Output
Print one integer — any positive integer value of xx so there is an integer k>1k>1 that x+2x+4x+⋯+2k−1x=nx+2x+4x+⋯+2k−1x=n.
Example
input
Copy
7 3 6 7 21 28 999999999 999999984
output
Copy
1 2 1 7 4 333333333 333333328
Note
In the first test case of the example, one of the possible answers is x=1,k=2x=1,k=2. Then 1⋅1+2⋅11⋅1+2⋅1 equals n=3n=3.
In the second test case of the example, one of the possible answers is x=2,k=2x=2,k=2. Then 1⋅2+2⋅21⋅2+2⋅2 equals n=6n=6.
In the third test case of the example, one of the possible answers is x=1,k=3x=1,k=3. Then 1⋅1+2⋅1+4⋅11⋅1+2⋅1+4⋅1 equals n=7n=7.
In the fourth test case of the example, one of the possible answers is x=7,k=2x=7,k=2. Then 1⋅7+2⋅71⋅7+2⋅7 equals n=21n=21.
In the fifth test case of the example, one of the possible answers is x=4,k=3x=4,k=3. Then 1⋅4+2⋅4+4⋅41⋅4+2⋅4+4⋅4 equals n=28n=28.
这个题一开始让我做真的是让我头疼坏了,直接模拟过程答案就不对,寻找素数就一直超时,其实cf最开始几个题目都是数学题,回归题目本身的描述就可以发现 x+2x+4x+⋯+2k−1x=nx+2x+4x+⋯+2k−1x=n就可以发现前面的式子是一个等比数列,然后求出等比数列前n项的和就可以把式子简化成这种形式
然后用1<
#include
using namespace std;
typedef long long ll;
ll t,n,pw;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
for(ll i=2;i<30;i++)
{
pw=(1<
B. Balanced Array
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given a positive integer nn, it is guaranteed that nn is even (i.e. divisible by 22).
You want to construct the array aa of length nn such that:
If there are multiple answers, you can print any. It is not guaranteed that the answer exists.
You have to answer tt independent test cases.
Input
The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases. Then tt test cases follow.
The only line of the test case contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the length of the array. It is guaranteed that that nn is even (i.e. divisible by 22).
It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105 (∑n≤2⋅105∑n≤2⋅105).
Output
For each test case, print the answer — "NO" (without quotes), if there is no suitable answer for the given test case or "YES" in the first line and any suitable array a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) satisfying conditions from the problem statement on the second line.
Example
input
Copy
5 2 4 6 8 10
output
Copy
NO YES 2 4 1 5 NO YES 2 4 6 8 1 3 5 11 NO
这个题目我觉得是昨晚最简单的题目,没什么难度,只要看代码就能理解,前面个%4稍微解释一下,因为会把这些数分成两组,如果每组的人数是奇数的话偶数部分的和不可能等于奇数部分,因为奇数部分的和永远是奇数,偶数部分永远是偶数,但如果每部分有偶数个,那么奇数部分和可以等于偶数制造了相等的机会
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
ll n,t;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
if(n%4!=0)
cout<<"NO"<
C. Alternating Subsequence
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Recall that the sequence bb is a a subsequence of the sequence aa if bb can be derived from aa by removing zero or more elements without changing the order of the remaining elements. For example, if a=[1,2,1,3,1,2,1]a=[1,2,1,3,1,2,1], then possible subsequences are: [1,1,1,1][1,1,1,1], [3][3] and [1,2,1,3,1,2,1][1,2,1,3,1,2,1], but not [3,2,3][3,2,3] and [1,1,1,1,2][1,1,1,1,2].
You are given a sequence aa consisting of nn positive and negative elements (there is no zeros in the sequence).
Your task is to choose maximum by size (length) alternating subsequence of the given sequence (i.e. the sign of each next element is the opposite from the sign of the current element, like positive-negative-positive and so on or negative-positive-negative and so on). Among all such subsequences, you have to choose one which has the maximum sum of elements.
In other words, if the maximum length of alternating subsequence is kk then your task is to find the maximum sum of elements of some alternating subsequence of length kk.
You have to answer tt independent test cases.
Input
The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases. Then tt test cases follow.
The first line of the test case contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of elements in aa. The second line of the test case contains nn integers a1,a2,…,ana1,a2,…,an (−109≤ai≤109,ai≠0−109≤ai≤109,ai≠0), where aiai is the ii-th element of aa.
It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105 (∑n≤2⋅105∑n≤2⋅105).
Output
For each test case, print the answer — the maximum sum of the maximum by size (length) alternating subsequence of aa.
Example
input
Copy
4 5 1 2 3 -1 -2 4 -1 -2 -1 -3 10 -2 8 3 8 -4 -15 5 -2 -3 1 6 1 -1000000000 1 -1000000000 1 -1000000000
output
Copy
2 -1 6 -2999999997
Note
In the first test case of the example, one of the possible answers is [1,2,3–,−1–––,−2][1,2,3_,−1_,−2].
In the second test case of the example, one of the possible answers is [−1,−2,−1–––,−3][−1,−2,−1_,−3].
In the third test case of the example, one of the possible answers is [−2–––,8,3,8–,−4–––,−15,5–,−2–––,−3,1–][−2_,8,3,8_,−4_,−15,5_,−2_,−3,1_].
In the fourth test case of the example, one of the possible answers is [1–,−1000000000–––––––––––––,1–,−1000000000–––––––––––––,1–,−1000000000–––––––––––––][1_,−1000000000_,1_,−1000000000_,1_,−1000000000_].
这个题目要找连续的符号相同的最大值累加起来即可,这个找最大值方法要好好总结一下
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
ll n,t;
ll a[200010];
int main()
{
cin>>t;
while(t--)
{
cin>>n;
for(ll i=1;i<=n;i++)
{
cin>>a[i];
}
if(n==1)
{
cout<maxx)
maxx=a[i];
}
sum+=maxx;
cout<
一上午过去了,今天先补三个题目吧,下回一定补四个以上