A:
题解: 可以for循环o(n2)的跑,满足题意描述则输出。
也可以看出性质当n=1时不存在,n大于1时a=n,b=n即可
A. Ehab and another construction problem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Given an integer xx, find 2 integers aa and bb such that:
- 1≤a,b≤x1≤a,b≤x
- bb divides aa (aa is divisible by bb).
- a?b>xa?b>x.
- ab
The only line contains the integer xx (1≤x≤100)(1≤x≤100).
Output
You should output two integers aa and bb, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes).
Examples
input
Copy
10
output
Copy
6 3
input
Copy
1
output
Copy
-1
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
B: 题解:
先将数组sort排序,之后标记一个tmp记录数组已经减过的值(初始化为0),然后从小到大遍历若a [i]-tmp<=0则continue 否则将tmp+=(a[i]-tmp) 并将该数输出。在遍历过程中若m用完则跳出 没用完则在最后补上相应的0.
B. Ehab and subtraction
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You're given an array aa. You should repeat the following operation kk times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0.
Input
The first line contains integers nn and kk (1≤n,k≤105)(1≤n,k≤105), the length of the array and the number of operations you should perform.
The second line contains nn space-separated integers a1,a2,…,ana1,a2,…,an (1≤ai≤109)(1≤ai≤109), the elements of the array.
Output
Print the minimum non-zero element before each operation in a new line.
Examples
input
Copy
3 5 1 2 3
output
Copy
1 1 1 0 0
input
Copy
4 2 10 3 5 3
output
Copy
3 2
Note
In the first sample:
In the first step: the array is [1,2,3][1,2,3], so the minimum non-zero element is 1.
In the second step: the array is [0,1,2][0,1,2], so the minimum non-zero element is 1.
In the third step: the array is [0,0,1][0,0,1], so the minimum non-zero element is 1.
In the fourth and fifth step: the array is [0,0,0][0,0,0], so we printed 0.
In the second sample:
In the first step: the array is [10,3,5,3][10,3,5,3], so the minimum non-zero element is 3.
In the second step: the array is [7,0,2,0][7,0,2,0], so the minimum non-zero element is 2.
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
C: 题解:
构造题,只能进行n+1次操作且只能加或者模,因为x最大1e6,而ai最大1e5.所以可以自然的想到先将所有的数都加到一个大数,然后再逐个取模,因为一个很小的数模上一个很大的数不影响结果,所以可以从头往后进行且不影响之前取模的值。
取模操作为2 i a[i]+MAX-i 这样取模后的值就等于i了
C. Ehab and a 2-operation task
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You're given an array aa of length nn. You can perform the following operations on it:
- choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (0≤x≤106)(0≤x≤106), and replace ajaj with aj+xaj+x for all (1≤j≤i)(1≤j≤i), which means add xxto all the elements in the prefix ending at ii.
- choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (1≤x≤106)(1≤x≤106), and replace ajaj with aj%xaj%x for all (1≤j≤i)(1≤j≤i), which means replace every element in the prefix ending at ii with the remainder after dividing it by xx.
Input
The first line contains an integer nn (1≤n≤2000)(1≤n≤2000), the number of elements in the array aa.
The second line contains nn space-separated integers a1a1, a2a2, ……, anan (0≤ai≤105)(0≤ai≤105), the elements of the array aa.
Output
On the first line, print the number of operations you wish to perform. On the next lines, you should print the operations.
To print an adding operation, use the format "11 ii xx"; to print a modding operation, use the format "22 ii xx". If ii or xx don't satisfy the limitations above, or you use more than n+1n+1 operations, you'll get wrong answer verdict.
Examples
input
Copy
3 1 2 3
output
Copy
0
input
Copy
3 7 6 3
output
Copy
2 1 1 1 2 2 4
Note
In the first sample, the array is already increasing so we don't need any operations.
In the second sample:
In the first step: the array becomes [8,6,3][8,6,3].
In the second step: the array becomes [0,2,3][0,2,3].
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
D:
题解:
从题目给的62次查询可以想到遍历这30位数,每个位进行2次查询来确定关系。
之后我们可以想到当1-i的大小确定的时候 对于第i位的判断只要进行最多2次即可。
首先我们将i+1至n的位做清0处理(即xor其本身)
在已知该1-i的大小若对该位两数都对1xor如果大小改变则a b在该位上有且只有一个为1且无需另加操作即可判断。
但此时我们需要更新1-(i-1)的大小关系。
若关系相等则必定都为1或者必定都为0,且1-i的大小关系必定与1-(i-1)的关系一样。
这样刚好两次就可以判断出一个位上的数
题面:
D. Ehab and another another xor problem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This is an interactive problem!
Ehab plays a game with Laggy. Ehab has 2 hidden integers (a,b)(a,b). Laggy can ask a pair of integers (c,d)(c,d) and Ehab will reply with:
- 1 if a⊕c>b⊕da⊕c>b⊕d.
- 0 if a⊕c=b⊕da⊕c=b⊕d.
- -1 if a⊕c
Laggy should guess (a,b)(a,b) with at most 62 questions. You'll play this game. You're Laggy and the interactor is Ehab.
It's guaranteed that 0≤a,b<2300≤a,b<230.
Input
See the interaction section.
Output
To print the answer, print "! a b" (without quotes). Don't forget to flush the output after printing the answer.
Interaction
To ask a question, print "? c d" (without quotes). Both cc and dd must be non-negative integers less than 230230. Don't forget to flush the output after printing any question.
After each question, you should read the answer as mentioned in the legend. If the interactor replies with -2, that means you asked more than 62 queries and your program should terminate.
To flush the output, you can use:-
- fflush(stdout) in C++.
- System.out.flush() in Java.
- stdout.flush() in Python.
- flush(output) in Pascal.
- See the documentation for other languages.
To hack someone, print the 2 space-separated integers aa and bb (0≤a,b<230)(0≤a,b<230).
Example
input
Copy
1 -1 0
output
Copy
? 2 1 ? 1 2 ? 2 0 ! 3 1
Note
In the sample:
The hidden numbers are a=3a=3 and b=1b=1.
In the first query: 3⊕2=13⊕2=1 and 1⊕1=01⊕1=0, so the answer is 1.
In the second query: 3⊕1=23⊕1=2 and 1⊕2=31⊕2=3, so the answer is -1.
In the third query: 3⊕2=13⊕2=1 and 1⊕0=11⊕0=1, so the answer is 0.
Then, we printed the answer.
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
【Codeforces Round #525(Div.2) A-D】
推荐阅读
- codeforces B. Young Explorers
- codeforces C. Mere Array
- codeforces D. Omkar and Bed Wars
- codeforces C. Omkar and Waterslide
- codeforces B. Omkar and Infinity Clock
- codeforces B. Ternary Sequence
- 题库-CF|【Codeforces Round 370 (Div 2) E】【线段树 等比数列 区间合并】Memory and Casinos 赌场区间[l,r] l进r先出的概率
- 题库-CF|【Codeforces Round 263 (Div 2)C】【贪心 哈弗曼思维】Appleman and Toastman 每个非1size子树延展为2子树的最大权
- Codeforces|Codeforces Round #605 (Div. 3) D. Remove One Element
- Codeforces|Codeforces Round #643 (Div. 2) B.Young Explorers