A. Sum of Odd Integers
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output
You are given two integers n
n
and k
k
. Your task is to find if n
n
can be represented as a sum of k
k
distinct positive odd (not divisible by 2
2
) integers or not.
You have to answer t
t
independent test cases.
Input
The first line of the input contains one integer t
t
(1≤t≤10 5
1≤t≤105
) — the number of test cases.
The next t
t
lines describe test cases. The only line of the test case contains two integers n
n
and k
k
(1≤n,k≤10 7
1≤n,k≤107
).
Output
For each test case, print the answer — “YES” (without quotes) if n
n
can be represented as a sum of k
k
distinct positive odd (not divisible by 2
2
) integers and “NO” otherwise.
Example
Input
Copy
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
Copy
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3
3
as 3
3
.
In the second test case, the only way to represent 4
4
is 1+3
1+3
.
In the third test case, you cannot represent 10
10
as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10
10
as 3+7
3+7
, for example.
In the fifth test case, you can represent 16
16
as 1+3+5+7
1+3+5+7
.
In the sixth test case, you cannot represent 16
16
as the sum of five distinct positive odd integers.
题意:给定n和k 问n是否能被k个不同奇数相加得到
思路:举几个例子看的出来 并且 奇数 + 奇数 = 偶数 偶数 + 奇数 = 奇数 所以 n和k的奇偶性应该一致
然后自信满满交一发 wa了 但是k个互不相同的奇数可以表示的最小数是k∗k 所以 n >= k*k
#include
using namespace std;
#define LL long long
#define pb(x) push_back(x)
#define debug(x) cout<<"..........."<
#define fi first
#define se second
const int N = 1e5+5;
const int M = 1e3+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
int main()
{
int t;
cin >> t;
while(t --)
{
LL n,k;
cin >> n >> k;
if((n%2 == 0 && k%2 == 0) || (n%2 == 1 && k%2 == 1))
{
if(n >= k*k)
cout << "YES" << '\n';
else
cout << "NO" << '\n';
}
else
cout << "NO" << '\n';
}
return 0;
}
B.
题意:题目有点长 意思就是有n个公主 每个公主可以有k个王子配对 优先选择编号小的 当然王子只能被选择一次 问配对成功最大数量
思路: 看到以为是二分图 然后其实只要模拟就好 优先选择编号小的 记录没有选到的公主编号 选过标记就完事
#include
using namespace std;
const int N = 1e5 + 5;
vector <int> a[N];
int vis[N];
int main()
{
int t;
cin >> t;
while(t --)
{
int n;
cin >> n;
for(int i = 1;i <= n;i ++)
{
a[i].clear();
vis[i] = 0;
}
int cnt = 0;
int m = 0;
for(int i = 1; i <= n; i ++)
{
int k;
cin >> k;
bool flag = 1;
for(int j = 0;j < k;j ++)
{
int x;
cin >> x;
a[i].push_back(x);
}
for(int j = 0;j < k;j ++)
{
int x = a[i][j];
if(!vis[x])
{
vis[x] = 1;
cnt ++ ;
flag = 0;
break;
}
}
if(flag)
m = i;
}
if(cnt == n)
cout << "OPTIMAL" << '\n';
else
{
cout << "IMPROVE" << '\n';
cout << m << ' ';
for(int i = 1;i <= n;i ++)
{
if(!vis[i])
{
cout << i << '\n';
break;
}
}
}
}
return 0;
}
C. Game with Chips
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
Petya has a rectangular Board of size n×m
n×m
. Initially, k
k
chips are placed on the board, i
i
-th chip is located in the cell at the intersection of sx i
sxi
-th row and sy i
syi
-th column.
In one action, Petya can move all the chips to the left, right, down or up by 1
1
cell.
If the chip was in the (x,y)
(x,y)
cell, then after the operation:
• left, its coordinates will be (x,y−1)
(x,y−1)
;
• right, its coordinates will be (x,y+1)
(x,y+1)
;
• down, its coordinates will be (x+1,y)
(x+1,y)
;
• up, its coordinates will be (x−1,y)
(x−1,y)
.
If the chip is located by the wall of the board, and the action chosen by Petya moves it towards the wall, then the chip remains in its current position.
Note that several chips can be located in the same cell.
For each chip, Petya chose the position which it should visit. Note that it’s not necessary for a chip to end up in this position.
Since Petya does not have a lot of free time, he is ready to do no more than 2nm
2nm
actions.
You have to find out what actions Petya should do so that each chip visits the position that Petya selected for it at least once. Or determine that it is not possible to do this in 2nm
2nm
actions.
Input
The first line contains three integers n,m,k
n,m,k
(1≤n,m,k≤200
1≤n,m,k≤200
) — the number of rows and columns of the board and the number of chips, respectively.
The next k
k
lines contains two integers each sx i ,sy i
sxi,syi
(1≤sx i ≤n,1≤sy i ≤m
1≤sxi≤n,1≤syi≤m
) — the starting position of the i
i
-th chip.
The next k
k
lines contains two integers each fx i ,fy i
fxi,fyi
(1≤fx i ≤n,1≤fy i ≤m
1≤fxi≤n,1≤fyi≤m
) — the position that the i
i
-chip should visit at least once.
Output
In the first line print the number of operations so that each chip visits the position that Petya selected for it at least once.
In the second line output the sequence of operations. To indicate operations left, right, down, and up, use the characters L,R,D,U
L,R,D,U
respectively.
If the required sequence does not exist, print -1 in the single line.
Examples
Input
Copy
3 3 2
1 2
2 1
3 3
3 2
Output
Copy
3
DRD
Input
Copy
5 4 3
3 4
3 1
3 3
5 3
1 3
1 4
Output
Copy
9
DDLUUUURR
题意:给出k个点 和 对应的 k个点的必须到达的位置 求能够到达所有点的最小方案 且 步数不超过2nm
思路:题目没说要最短的路径 我们把所有点移到左上角然后把整个图遍历一遍 就算是极端情况步数也不会超过2nm
#include
using namespace std;
#define LL long long
#define pb(x) push_back(x)
#define debug(x) cout<<"..........."<
#define fi first
#define se second
const int N = 205;
const int M = 1e3+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
int main()
{
int n,m, k ;
cin >> n >> m >> k ;
int x,y;
for(int i = 1; i <= k ; i ++)
cin >> x >> y >> x >> y;
string res = "";
for(int i = 1; i <= n - 1; i ++)
res += 'U';
for(int i = 1; i <= m - 1; i ++)
res += 'L';
bool flag = 1;
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= m - 1; j ++)
{
if(flag)
res += 'R';
else
res += 'L';
}
flag ^= 1;
res += 'D';
}
cout << res.size() << '\n' << res << '\n';
return 0;
}