强势推荐页游一枚
codeforces,简称CF。
与全球玩家一起天梯上分。
全球同服,万人竞技
春节期间,福利多多
年二十九到大年初二
一连加开四场排位赛
支持多种语言,
C/C++, Pascal, Java, C#, Python,
Ruby, Perl, PHP, Haskell, Scala,OCaml,
Go, D, JavaScript, Rust and Kotlin.
激情刺激,惊险过瘾
运筹帷幄,攻题拔寨
是兄弟就一起CF上分吧
体验一战变灰的快感吧
你还在等待什么呢
人生第一场CF
①AC了第一题②AC了第二题③卡在了第三题最后30分钟AC了④最后1分钟调出了第四题⑤第四题没来得及交上去⑥第二题FST了
CF真好玩
一二题太水了一篇博客够了
我怎么只有一个C币了  ̄~ ̄#)
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x1,x2,…,xn, correspondingly. One of the participants wrote down this sequence in a notebook.
They visited it again the following day, and the number of stones in piles was equal to y1,y2,…,yn. One of the participants also wrote it down in a notebook.
It is well known that every member of the EJOI jury during the night either sits in the room 108 or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.
Participants want to know whether their notes can be correct or they are sure to have made a mistake.
The first line of the input file contains a single integer n, the number of piles with stones in the garden (1≤n≤50).
The second line contains n integers separated by spaces x1,x2,…,xn, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time (0≤xi≤1000).
The third line contains n integers separated by spaces y1,y2,…,yn, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time (0≤yi≤1000).
If the records can be consistent output “Yes”, otherwise output “No” (quotes for clarity).
input
5
1 2 3 4 5
2 1 4 3 5
output
Yes
input
5
1 1 1 1 1
1 0 1 0 1
output
Yes
input
3
2 3 9
1 7 9
output
No
In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.
In the second example, the jury took stones from the second and fourth piles.
It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array.
懒得╮(╯▽╰)╭
给定两串数列,每串数列有n个数,代表n堆石头堆里的石头数量,问通过无数次的“取走一个石头”和“移动一个石头”,能否使第一条数列变为第二条数列。
……还以为多难的。
这就比两堆石头哪堆石头多了就好了吗
#include
int Read()
{
int p=0;
char c=getchar();
while(c<'0' || c>'9')
c=getchar();
while(c>='0' && c<='9')
p=p*10+c-'0',c=getchar();
return p;
}
int N,x,a,b;
int main()
{
N=Read();
for(int i=1;i<=N;i++) a+=Read();
for(int i=1;i<=N;i++) b+=Read();
puts(a>=b?"Yes":"No");
}
time limit per test 1 second
memory limit per test 256 megabytes
inputstandard input
outputstandard output
There is an array with n elements a1, a2, …, an and the number x.
In one operation you can select some i (1 ≤ i ≤ n) and replace element ai with ai & x, where & denotes the bitwise and operation.
You want the array to have at least two equal elements after applying some operations (possibly, none). In other words, there should be at least two distinct indices i ≠ j such that ai = aj. Determine whether it is possible to achieve and, if possible, the minimal number of operations to apply.
The first line contains integers n and x (2 ≤ n ≤ 100 000, 1 ≤ x ≤ 100 000), number of elements in the array and the number to and with.
The second line contains n integers ai (1 ≤ ai ≤ 100 000), the elements of the array.
Print a single integer denoting the minimal number of operations to do, or -1, if it is impossible.
input
4 3
1 2 3 7
output
1
input
2 228
1 1
output
0
input
3 7
1 2 3
output
-1
In the first example one can apply the operation to the last element of the array. That replaces 7 with 3, so we achieve the goal in one move.
In the second example the array already has two equal elements.
In the third example applying the operation won’t change the array at all, so it is impossible to make some pair of elements equal.
给定一串有n个数的数列和一个自然数x,记一次操作为将数列中的某个数a改为a&x,问最少经过几次操作能使数列中出现两个相同的数。
0&0=0 0&0=0
1&0=0 1&0=0 0&0=0
0&1=0 1&0=0 0&0=0
1&1=1 1&1=1
如果你看懂了上面的引用块(虽然引用的是我自己的),你就会明白我想说的是:
(a&x)=(a&x&x)=(a&x&x&x)=(a&x&x&x&x)……
回到这个题,也就是说将数列中的某个数a改为a&x
这个操作对于每个a都最多进行一次。(如果多于一次与只有一次是等效的, 白白浪费步数)
那么答案只会有四个:
0:一开始的数列就有一样的
1:将某个a[i]&x后等于另一个a[j]
2:存在a[i]&x=a[j]&x
-1:以上三种都不存在
最近脑子不好用讲话和码代码都很奇怪
因为桶计数的时候要考虑到是本来就有的数还是&了一次后的数,所以开了bin和nib两个桶
之前因为只有一个桶导致答案是1的数据输出了2
#include
#include
#include
#include
#include
using namespace std;
void Read(int &p)
{
p=0;
char c=getchar();
while(c<'0' || c>'9')
c=getchar();
while(c>='0' && c<='9')
p=p*10+c-'0',c=getchar();
}
int n,x,a[102018],bin[102018],nib[102018];
int main()
{
Read(n); Read(x);
for(int i=1;i<=n;i++)
{
Read(a[i]),bin[a[i]]++;
if(bin[a[i]]>1)
{
puts("0");
return 0;
}
}
for(int i=1;i<=n;i++)
if((a[i]&x)!=a[i])
{
nib[a[i]&x]++;
if(bin[a[i]&x])
{
puts("1");
return 0;
}
}
for(int i=1;i<=n;i++)
if(nib[a[i]&x]>1)
{
puts("2");
return 0;
}
puts("-1");
return 0;
}