time : 2020/08/14
链接
Boboniu gives you
He allows you to do the following operation as many times as you want:
You should answer if it’s possible to arrange all the balls into a palindrome after several (possibly zero) number of described operations.
The first line contains one integer T (1≤T≤100) denoting the number of test cases.
For each of the next T cases, the first line contains four integers r, g, b and w (0≤r,g,b,w≤109).
For each test case, print “Yes” if it’s possible to arrange all the balls into a palindrome after doing several (possibly zero) number of described operations. Otherwise, print “No”.
4
0 1 1 1
8 1 9 3
0 0 0 0
1000000000 1000000000 1000000000 1000000000
No
Yes
Yes
Yes
In the first test case, you’re not able to do any operation and you can never arrange three balls of distinct colors into a palindrome.
In the second test case, after doing one operation, changing (8,1,9,3) to (7,0,8,6), one of those possible palindromes may be “rrrwwwbbbbrbbbbwwwrrr”.
A palindrome is a word, phrase, or sequence that reads the same backwards as forwards. For example, “rggbwbggr”, “b”, “gg” are palindromes while “rgbb”, “gbbgr” are not. Notice that an empty word, phrase, or sequence is palindrome.
首先考虑一个问题,r,g,b,w四种字符怎么才能构成回文串?如果这四种字符的个数都是偶数的话,显而易见可以构成回文串,比如rgbwwbgr 按类似的方法就行。 再考虑一个问题,每次操作都能将一组r,g,b转换成w。这个操作我们能做几次?换句话说做几次是必要的,假如说我们执行了两次操作,将两组r,g,b转换成6个w。我们可以发现他们每种字符的个数奇偶性并没有发生改变,所以如果执行偶数次操作就纯属闲的。如果执行三次呢?其实跟执行一次没有什么区别,我们并不关心每种字符有几个,我们只关心每种字符的奇偶性,有回文串的对称性可以知道最多只能有一种字符的个数是奇数个。所以问们只用考虑r,g,b,w的个数中有几个奇数就行。或者如果r,g,b个数不为零时转换一次,再看奇数的个数就行了。
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* Author Information
* Author: JokerNoCry
* Time: 2020-08-12 22:44:00
* QQ:1160860141
**/
#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a
#define ll long long
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;
int r,g,b,w;
int r1,g1,b1,w1;
scanf("%d",&t);
while(t--)
{
int count = 0;
scanf("%d%d%d%d",&r,&g,&b,&w);
count+=r%2;
count+=g%2;
count+=b%2;
count+=w%2;
if(count<=1) printf("Yes\n");
else
{
if(r!=0 && g!= 0 && b!=0)
{
r1=--r;
g1=--g;
b1=--b;
w1=w+3;
count = 0;
count+=r1%2;
count+=g1%2;
count+=b1%2;
count+=w1%2;
//printf("%d %d %d %d\n",r1,g1,b1,w1);
if(count<=1) printf("Yes\n");
else printf("No\n");
}else printf("No\n");
}
}
return 0;
}
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a n×m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (Sx,Sy) which is not on the border (i.e. 2≤Sx≤n−1 and 2≤Sy≤m−1).
From the cell (x,y), you can move your chess piece to (x,y′) (1≤y′≤m,y′≠y) or (x′,y) (1≤x′≤n,x′≠x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
The only line of the input contains four integers n, m, Sx and Sy (3≤n,m≤100, 2≤Sx≤n−1, 2≤Sy≤m−1) — the number of rows, the number of columns, and the initial position of your chess piece, respectively.
You should print n⋅m lines.
The i-th line should contain two integers xi and yi (1≤xi≤n, 1≤yi≤m), denoting the i-th cell that you visited. You should print exactly nm pairs (xi,yi), they should cover all possible pairs (xi,yi), such that 1≤xi≤n, 1≤yi≤m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
3 3 2 2
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
3 4 2 2
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Possible routes for two examples:
我们思考一个问题,我们的棋子是车,我们可以在一条直线上任意移动,那这题不就简单了,我们一定能到达图上的任何一个位置,必然能遍历全图,而且没有任何条件限制,(因为我们可以在一行或一列中任意跳转,只要有空位就能走。)所以我们只用找到一种走的路径就行,我们可以这样,一行一行的走,走完一行换下一行,由于我们初始点不在边界,所以我们就能保证每行遍历结束后的点在第一个或者最后一个,就这样遍历就行。
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* Author Information
* Author: JokerNoCry
* Time: 2020-08-12 23:03:55
* QQ:1160860141
**/
#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a
#define ll long long
using namespace std;
int n,m,sx,sy;
int vis[110][110];
int vis_c[110];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
memset(vis,0,sizeof(vis));
memset(vis_c,0,sizeof(vis_c));
scanf("%d%d%d%d",&m,&n,&sx,&sy);
printf("%d %d\n",sx,sy);
vis[sx][sy] = 1;
vis_c[sx] = 1;
for(int i=1;i<=n;i++)
{
if(vis[sx][i]!=1)
{
vis[sx][i] = 1;
printf("%d %d\n",sx,i);
}
}
int now = n;
for(int i=1;i<=m;i++)
{
if(vis_c[i] == 1) continue;
else vis_c[i] = 1;
if(now == n)
{
for(;now>=1;now--)
{
if(vis[i][now]!=1)
{
vis[i][now]=1;
printf("%d %d\n",i,now);
}
}
now = 1;
}else if(now==1)
{
for(;now<=n;now++)
{
if(vis[i][now]!=1)
{
vis[i][now] = 1;
printf("%d %d\n",i,now);
}
}
now = n;
}
}
return 0;
}
Boboniu likes bit operations. He wants to play a game with you.
Boboniu gives you two sequences of non-negative integers a1,a2,…,an and b1,b2,…,bm.
For each i (1≤i≤n), you’re asked to choose a j (1≤j≤m) and let ci=ai&bj, where & denotes the bitwise AND operation . Note that you can pick the same j for different i’s.
Find the minimum possible c1|c2|…|cn, where | denotes the bitwise OR operation.
The first line contains two integers n and m (1≤n,m≤200).
The next line contains n integers a1,a2,…,an (0≤ai<29).
The next line contains m integers b1,b2,…,bm (0≤bi<29).
Print one integer: the minimum possible c1|c2|…|cn.
4 2
2 6 4 0
2 4
2
7 6
1 9 1 9 8 1 0
1 1 4 5 1 4
0
8 5
179 261 432 162 82 43 10 38
379 357 202 184 197
147
For the first example, we have c1=a1&b2=0, c2=a2&b1=2, c3=a3&b1=0, c4=a4&b1=0.Thus c1|c2|c3|c4=2, and this is the minimal answer we can get.
这题困我许久,说说正确思路吧。
我们首先应该明白一个规律,如果 A1 | A2 | A3 | … | An == i 成立的话,那么对于任意一个Ai 都有Ai | i == i 由于a和b的范围都小于29 所以OR的结果也不可能超过29;29 = 512 我们枚举0 ~ 512 然后判断对于每一个Ai 是否有一个 Bj 使得 Ai & Bj 等于枚举的数就行。
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* Author Information
* Author: JokerNoCry
* Time: 2020-08-14 18:53:52
* QQ:1160860141
**/
#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a
#define ll long long
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,m;
int a[210],b[210];
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=m;i++) scanf("%d",&b[i]);
for(int ans=0;ans<=512;ans++)
{
bool flag_ans = true;
for(int i=1;i<=n;i++)
{
bool flag = false;
for(int j=1;j<=m;j++)
{
if(((a[i]&b[j])|ans) == ans)
{
flag = true;
break;
}
}
if(flag == false)
{
flag_ans = false;
break;
}
}
if(flag_ans == true)
{
printf("%d\n",ans);
break;
}
}
return 0;
}