混合训练三总结

[Fedya and Maths](https://vjudge.net/problem/CodeForces-456B)
Fedya studies in a gymnasium. Fedya’s maths hometask is to calculate the following expression:

(1^n + 2 ^ n + 3 ^n + 4 ^n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).

Input
The single line contains a single integer n (0 ≤ n ≤ 10105). The number doesn’t contain any leading zeroes.

Output
Print the value of the expression without leading zeros.

Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.

Note to the first sample:
在这里插入图片描述

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define maxn 1000005
char str[maxn],a,b;
long long ans;
int main()
{
    while(~scanf("%s",str))
    {
        int len=strlen(str);
        if(len>=2)
        {
            a=str[len-1];
            b=str[len-2];
            ans=(b-'0')*10+a-'0';
        }
        else
            ans=str[len-1]-'0';
        if(ans%4==0)
            printf("4\n");
        else
            printf("0\n");
    }
    return 0;
}

[Squares](https://vjudge.net/problem/CodeForces-263B/origin)
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let’s number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.

Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We’ll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.

Help Vasya find a point that would meet the described limits.

Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, …, an (1 ≤ ai ≤ 109).

It is guaranteed that all given squares are distinct.

Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.

If there is no answer, print “-1” (without the quotes).

Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1

#include<iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
const int N=51;
int arr[N],n,k,i,j,flag;
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    memset(arr,0,sizeof(arr));
    cin>>n>>k;
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n,cmp);
    if(k>n)
    {
        printf("-1\n");
        return 0;
    }
    else
    {
        printf("%d 0\n",arr[k-1]);
        return 0;
    }
}

[Domino](https://vjudge.net/problem/CodeForces-353A/origin)
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.

To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.

Input
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.

Output
Print a single number — the minimum required number of seconds. If Valera can’t do the task in any time, print  - 1.

Examples
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
Note
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn’t required to do anything.

In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.

In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<functional>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int MAXN=1005;
ll t,ans,cnt,sum,temp,Max,Min,s,i,j,k,n,high,lower;
char a[15];
int main()
{
	scanf("%d",&n);
	bool flag=false;
	for(i=1;i<=n;i++)
	{
	  int a,b;
	  scanf("%d%d",&a,&b);
	  if((a+b)%2) flag=true;
	  ans+=a;
	  cnt+=b;
	}
	if(!(ans%2)&&!(cnt%2))  printf("%d\n",0);
	else if((ans+cnt)%2) printf("%d\n",-1);
	else printf("%d\n",flag?1:-1);
 	return 0;
}

Round House
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.

Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b entrances in the direction of increasing numbers (in this order entrance n should be followed by entrance 1). The negative value of b corresponds to moving |b| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance n). If b = 0, then Vasya prefers to walk beside his entrance.

在这里插入图片描述
Illustration for n = 6, a = 2, b =  - 5.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.

Input
The single line of the input contains three space-separated integers n, a and b (1 ≤ n ≤ 100, 1 ≤ a ≤ n,  - 100 ≤ b ≤ 100) — the number of entrances at Vasya’s place, the number of his entrance and the length of his walk, respectively.

Output
Print a single integer k (1 ≤ k ≤ n) — the number of the entrance where Vasya will be at the end of his walk.

Examples
Input
6 2 -5
Output
3
Input
5 1 3
Output
4
Input
3 2 7
Output
3
Note
The first example is illustrated by the picture in the statements.

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<functional>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN=1005;
int main()
{
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    a = ((a - 1 + b) % n + n) % n + 1;
    printf("%d\n", a);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_46434074/article/details/106607255