您的位置:首页 > 其它

Codeforces Round #360 (Div. 2)

2016-06-30 07:33 441 查看
A. Opponents

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Arya has n opponents in the school. Each day he will fight with all opponents who
are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present
opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days
that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.

Input
The first line of the input contains two integers n and d (1 ≤ n, d ≤ 100) —
the number of opponents and the number of days, respectively.
The i-th of the
following d lines contains a string of length n consisting
of characters '0' and '1'. The j-th
character of this string is '0' if the j-th
opponent is going to be absent on the i-th day.

Output
Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents.

Examples

input
2 2
10
00


output
2


input
4 1
0100


output
1


input
4 5
11011111011010111111


output
2


Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and
his opponents will beat him on days 2 and 5.
Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
每次输入字符串,如果字符串中有0,就代表Arya赢了,计算Arya最大连续赢几局,手速依然太慢啊,加强锻炼要,代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
char str[105];
int n,d;
while(~scanf("%d%d",&n,&d))
{
int sum=0,flag=0;
int maxn=0;
for(int i=0;i<d;i++)
{
scanf("%s",str);
for(int i=0;i<strlen(str);i++)
{
if(str[i]=='0')
{
flag=1;
break;
}
}

if(flag)
sum++;
else
sum=0;
maxn=max(sum,maxn);
flag=0;
}
printf("%d\n",maxn);
}
return 0;
}


B. Lovely Palindromes

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are
palindrome numbers, while 112 and 1021 are
not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers
with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221),
so maybe she could see something in them.
Now Pari asks you to write a program that gets a huge integer n from
the input and tells what is the n-th even-length positive palindrome number?

Input
The only line of the input contains a single integer n (1 ≤ n ≤ 10100 000).

Output
Print the n-th
even-length palindrome number.

Examples

input
1


output
11


input
10


output
1001


Note
The first 10 even-length palindrome
numbers are 11, 22, 33, ... , 88, 99 and 1001.

 

直接输出字符串和其反串:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char str[100005],s[100005];
int main()
{

while(~scanf("%s",str))
{
int j=0;
for(int i=strlen(str)-1;i>=0;i--)
s[j++]=str[i];
s[j]='\0';
printf("%s%s\n",str,s);
}
return 0;
}


C. NP-Hard Problem

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph G is
given. Subset A of its vertices is called a vertex
cover of this graph, if for each edge uv there is at least
one endpoint of it in this set, i.e. 

 or 

 (or
both).
Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex
cover.
They have agreed to give you their graph and you need to find two disjoint subsets of its
vertices A and B,
such that both A and B are
vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself).

Input
The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) —
the number of vertices and the number of edges in the prize graph, respectively.
Each of the next m lines
contains a pair of integers ui and vi (1  ≤  ui,  vi  ≤  n),
denoting an undirected edge between ui and vi.
It's guaranteed the graph won't contain any self-loops or multiple edges.

Output
If it's impossible to split the graph between Pari and Arya as they expect, print "-1"
(without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single
integer k denoting the number of vertices in that vertex cover, and the second
line contains kintegers — the indices of vertices. Note that because of m ≥ 1,
vertex cover cannot be empty.

Examples

input
4 21 22 3


output
1221 3


input
3 3
1 22 3
1 3


output
-1


Note
In the first sample, you can give the vertex number 2 to
Arya and vertices numbered 1 and 3 to
Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya.

 DFS二分图染色,不会啊,附大牛博客
二分图染色

D. Remainders Game

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer x and k,
and tells Arya k but not x.
Arya have to find the value 

.
There are n ancient numbers c1, c2, ..., cn and
Pari has to tell Arya 

 if
Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy
independent of value of x or not. Formally, is it true that Arya can understand
the value 

 for
any positive integer x?
Note, that 

 means
the remainder of x after dividing it by y.

Input
The first line of the input contains two integers n and k (1 ≤ n,  k ≤ 1 000 000) —
the number of ancient integers and value k that is chosen by Pari.
The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000).

Output
Print "Yes" (without quotes) if Arya has a winning strategy independent of value
of x, or "No"
(without quotes) otherwise.

Examples

input
4 5
2 3 5 12


output
Yes


input
2 7
2 3


output
No


Note
In the first sample, Arya can understand 

 because 5 is
one of the ancient numbers.
In the second sample, Arya can't be sure what 

 is.
For example 1 and 7 have
the same remainders after dividing by 2 and 3,
but they differ in remainders after dividing by 7.
中国剩余定理,见中国剩余定理

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

long long gcd(long long a,long long b)
{
if(b==0) return a;
return gcd(b,a%b);
}
int main()
{
long long n,k;
while(~scanf("%lld%lld",&n, &k))
{
long long x,sum =  1;
for (int i=0;i<n;i++)
{
scanf("%lld",&x);
sum = x / gcd(x, sum)*sum % k;//求最小公倍数
}
if(sum==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
看见了一些大牛的代码,看见有
std::__gcd(c, k);

貌似是#include<algorithm>头文件里面的库函数,这里记一下,以后可以直接用了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: