【LDU】2017级个人训练赛#1

A - The Artful Expedient

http://codeforces.com/problemset/problem/869/A

Rock... Paper!

After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.

A positive integer n is decided first. Both Koyomi and Karen independently choose n distinct positive integers, denoted by x1, x2, ..., xn and y1, y2, ..., yn respectively. They reveal their sequences, and repeat until all of 2n integers become distinct, which is the only final state to be kept and considered.

Then they count the number of ordered pairs (i, j) (1 ≤ i, j ≤ n) such that the value xi xor yj equals to one of the 2n integers. Here xormeans the bitwise exclusive or operation on two integers, and is denoted by operators ^ and/or xor in most programming languages.

Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game.

Input

The first line of input contains a positive integer n (1 ≤ n ≤ 2 000) — the length of both sequences.

The second line contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 2·106) — the integers finally chosen by Koyomi.

The third line contains n space-separated integers y1, y2, ..., yn (1 ≤ yi ≤ 2·106) — the integers finally chosen by Karen.

Input guarantees that the given 2n integers are pairwise distinct, that is, no pair (i, j) (1 ≤ i, j ≤ n) exists such that one of the following holds: xi = yji ≠ j and xi = xji ≠ j and yi = yj.

Output

Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.

Examples
input
3
1 2 3
4 5 6
output
Karen
input
5
2 4 6 8 10
9 7 5 3 1
output
Karen
Note

In the first example, there are 6 pairs satisfying the constraint: (1, 1)(1, 2)(2, 1)(2, 3)(3, 2) and (3, 3). Thus, Karen wins since 6 is an even number.

In the second example, there are 16 such pairs, and Karen wins again.


#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

You are given two lists of non-zero digits.

Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 9) — the lengths of the first and the second lists, respectively.

The second line contains n distinct digits a1, a2, ..., an (1 ≤ ai ≤ 9) — the elements of the first list.

The third line contains m distinct digits b1, b2, ..., bm (1 ≤ bi ≤ 9) — the elements of the second list.

Output

Print the smallest pretty integer.

Examples
input
2 3
4 2
5 7 6
output
25
input
8 8
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1
output
1
Note

In the first example 254624567 are pretty, as well as many other integers. The smallest among them is 2542 and 24 are not pretty because they don't have digits from the second list.

In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.


#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

You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get?

Definitions of subsegment and array splitting are given in notes.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤  105) — the size of the array a and the number of subsegments you have to split the array to.

The second line contains n integers a1,  a2,  ...,  an ( - 109  ≤  ai ≤  109).

Output

Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments.

Examples
input
5 2
1 2 3 4 5
output
5
input
5 1
-4 -5 -3 -2 -1
output
-5
Note

A subsegment [l,  r] (l ≤ r) of array a is the sequence al,  al + 1,  ...,  ar.

Splitting of array a of n elements into k subsegments [l1, r1][l2, r2], ..., [lk, rk] (l1 = 1rk = nli = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark).

In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result.

In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4,  - 5,  - 3,  - 2,  - 1). The only minimum is min( - 4,  - 5,  - 3,  - 2,  - 1) =  - 5. The resulting maximum is  - 5.





    #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

Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:

"Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that barn for three days and three nights. But they overlooked and there remained a little hole in the barn, from which every day sparrows came through. Here flew a sparrow, took a grain and flew away..."

More formally, the following takes place in the fairy tale. At the beginning of the first day the barn with the capacity of n grains was full. Then, every day (starting with the first day) the following happens:

  • m grains are brought to the barn. If m grains doesn't fit to the barn, the barn becomes full and the grains that doesn't fit are brought back (in this problem we can assume that the grains that doesn't fit to the barn are not taken into account).
  • Sparrows come and eat grain. In the i-th day i sparrows come, that is on the first day one sparrow come, on the second day two sparrows come and so on. Every sparrow eats one grain. If the barn is empty, a sparrow eats nothing.

Anton is tired of listening how Danik describes every sparrow that eats grain from the barn. Anton doesn't know when the fairy tale ends, so he asked you to determine, by the end of which day the barn will become empty for the first time. Help Anton and write a program that will determine the number of that day!

Input

The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018) — the capacity of the barn and the number of grains that are brought every day.

Output

Output one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one.

Examples
input
5 2
output
4
input
8 1
output
5
Note

In the first sample the capacity of the barn is five grains and two grains are brought every day. The following happens:

  • At the beginning of the first day grain is brought to the barn. It's full, so nothing happens.
  • At the end of the first day one sparrow comes and eats one grain, so 5 - 1 = 4 grains remain.
  • At the beginning of the second day two grains are brought. The barn becomes full and one grain doesn't fit to it.
  • At the end of the second day two sparrows come. 5 - 2 = 3 grains remain.
  • At the beginning of the third day two grains are brought. The barn becomes full again.
  • At the end of the third day three sparrows come and eat grain. 5 - 3 = 2 grains remain.
  • At the beginning of the fourth day grain is brought again. 2 + 2 = 4 grains remain.
  • At the end of the fourth day four sparrows come and eat grain. 4 - 4 = 0 grains remain. The barn is empty.

So the answer is 4, because by the end of the fourth day the barn becomes empty.


#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.

Input

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.

Output

On the single line of the output print the number of groups of magnets.

Examples
input
6
10
10
10
01
10
10
output
3
input
4
01
01
10
10
output
2
Note

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

You will get several non-negative integer n (n <= 1,000,000) from input file. Each one is in a line by itself.

The input is terminated by a line with a negative integer.

 Output

For each n, you should print exactly one word ("YES" or "NO") in a single line. No extra spaces are allowed.

 Sample Input

9-1

 Sample Output

YES

#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

Problem Description
HazelFan is given two positive integers  a,b , and he wants to calculate  amodb . But now he forgets the value of  b  and only remember the value of  a , please tell him the number of different possible results.
 

Input
The first line contains a positive integer  T(1T5) , denoting the number of test cases.
For each test case:
A single line contains a positive integer  a(1a109) .
 

Output
For each test case:
A single line contains a nonnegative integer, denoting the answer.
 

Sample Input
  
  
2 1 3
 

Sample Output
  
  
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;


}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值