A - The Artful Expedient
http://codeforces.com/problemset/problem/869/A
#include<stdio.h>
const int maxn=2e6+10;
int vis[2*maxn];
int a[maxn];
int b[maxn];
int main()
{
int i,j,k,n;
while(scanf("%d",&n)!=EOF)
{
k=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
vis[a[i]]=1;
}
for(i=1;i<=n;i++)
{
scanf("%d",&b[i]);
vis[b[i]]=1;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(vis[a[i]^b[j]])
{
k++;
}
}
}
if(k%2)
printf("Koyomi\n");
else
printf("Karen\n");
}return 0;
}
B - Search for Pretty Integers
http://codeforces.com/problemset/problem/870/A
#include<stdio.h>
#include<algorithm>
using namespace std;
int c[11]={0};
int main()
{
int n,m,i,j,k,flag=1;
int a[11],b[11];
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
c[a[i]]++;
}
for(i=0;i<m;i++)
{
scanf("%d",&b[i]);
c[b[i]]++;
}
sort(a,a+n);
sort(b,b+m);
for(i=1;i<10&&flag;i++)
{
if(c[i]>1)
{
printf("%d\n",i);
flag=0;
}
}
if(flag)
{
a[0]>b[0]?printf("%d%d\n",b[0],a[0]):printf("%d%d\n",a[0],b[0]);
}
return 0;
}
C - Maximum of Maximums of Minimums
http://codeforces.com/problemset/problem/870/B
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
int n,m,i,j;
ll a[100050],begin,end;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%lld",&a[i]);
if(i==0)
begin=a[i];
else if(i==n-1)
end=a[i];
}
sort(a,a+n);
if(n==1)
printf("%lld\n",a[0]);
else if(m==1)
printf("%lld\n",a[0]);
else if(m==2)
printf("%lld\n",max(begin,end));
else
printf("%lld",a[n-1]);
return 0;
}
D - Anton and Fairy Tale
http://codeforces.com/problemset/problem/785/C
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
typedef long long ll;
const ll N=2e9+10;
int main()
{
ll n,m;
scanf("%lld%lld",&n,&m);
if(m>=n)
{
printf("%lld",n);
return 0;
}
n-=m;
ll left=0,right=N,ans=0;
while(left<=right)
{
ll mid=(right+left)/2;
if(n>(1+mid)*mid/2)
left=mid+1;
else
{
right=mid-1;
ans=mid;
}
}
printf("%lld\n",ans+m);
return 0;
}
E - Magnets
http://codeforces.com/problemset/problem/344/A
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
On the single line of the output print the number of groups of magnets.
6 10 10 10 01 10 10
3
4 01 01 10 10
2
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets.
#include<stdio.h>
#include<string.h>
#define N 100050
int main()
{
int a[N];
int i,j,T;
char b[3];
scanf("%d",&T);
getchar();
for(i=1;i<=T;i++)
{
gets(b);
if(strcmp(b,"01"))
a[i]=0;
else
a[i]=1;
}
int k=a[1],cnt=1;
for(i=2;i<=T;i++)
{
if(!k^a[i])
{
k=a[i];
}
else if(k^a[i])
{
k=a[i];
cnt++;
}
}
printf("%d",cnt);
return 0;
}
F - Sum of Factorials
http://acm.fzu.edu.cn/problem.php?pid=1106
Problem Description
John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions to the foundations of mathematics, logic, quantum physics, meteorology, science, computers, and game theory. He was noted for a phenomenal memory and the speed with which he absorbed ideas and solved problems. In 1925 he received a B.S. diploma in chemical engineering from Zurich Institute and in 1926 a Ph.D. in mathematics from the University of Budapest. His Ph.D. dissertation on set theory was an important contribution to the subject. At the age of 20, von Neumann proposed a new definition of ordinal numbers that was universally adopted. While still in his twenties, he made many contributions in both pure and applied mathematics that established him as a mathematician of unusual depth. His Mathematical Foundations of Quantum Mechanics (1932) built a solid framework for the new scientific discipline. During this time he also proved the mini-max theorem of GAME THEORY. He gradually expanded his work in game theory, and with coauthor Oskar Morgenstern he wrote Theory of Games and Economic Behavior (1944).
There are some numbers which can be expressed by the sum of factorials. For example 9,9=1!+2!+3!. Dr. von Neumann was very interested in such numbers. So, he gives you a number n, and wants you to tell him whether or not the number can be expressed by the sum of some factorials.
Well, it's just a piece of cake. For a given n, you'll check if there are some xi, and let n equal to
If the answer is yes, say "YES"; otherwise, print out "NO".
Input
The input is terminated by a line with a negative integer.
Output
Sample Input
Sample Output
#include<stdio.h>
#include<string.h>
#define N 100050
int main()
{
int a[N];
int i,j,T;
char b[3];
scanf("%d",&T);
getchar();
for(i=1;i<=T;i++)
{
gets(b);
if(strcmp(b,"01"))
a[i]=0;
else
a[i]=1;
}
int k=a[1],cnt=1;
for(i=2;i<=T;i++)
{
if(!k^a[i])
{
k=a[i];
}
else if(k^a[i])
{
k=a[i];
cnt++;
}
}
printf("%d",cnt);
return 0;
}
G - Euler theorem
http://acm.hdu.edu.cn/showproblem.php?pid=6124
For each test case:
A single line contains a positive integer a(1≤a≤109) .
A single line contains a nonnegative integer, denoting the answer.
2 1 3
2 3
#include<stdio.h>
#include<math.h>
#include<algorithm>
typedef long long ll;
int main()
{
ll a,b;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&a);
if(a==1||a==2)
b=2;
else if(a%2==0)
b=a/2+1;
else
b=a/2+2;
printf("%lld\n",b);
}return 0;
}