2020 Niuke NOIP pre-match training camp-popular group (fourth game) first 3 questions

The fourth game

4. Necklace

1. time

Title description:

As we all know, the duration of the NOIP and its simulation games is 3 hours and 30 minutes.

Alice and Bob participated in the 2020 Niu Ke NOIP pre-match training camp-improvement group starting at h:m. Please tell them when the game ends.

Input format:

A total of one line: a string of the form hh:mm, indicating the time when the game starts. If the number of digits is insufficient, 0 will be filled.

Output format

A total of one line: a string of the form hh:mm, indicating the time when the game ends. Please fill in 0 if the number of digits is insufficient.

Sample input:
00:00
Sample output:
03:30
answer:

First change the input time into components before + ++ 210 (that is, 3 hours and 30 minutes), then mod1440 14401 4 4 0 Guaranteed that the number of hours does not exceed24 242 . 4
then÷ 60 \ div \ 60÷ 6 0  is divided, modulo60 606 0 is the point.

On the code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int a,b;
	scanf("%d:%d",&a,&b);
	int x=a*60+b+210;
	if(x>=1440)
	x=x%1440;
	int p=x/60;
	int y=x%60;
	//注意不足两位前面要添0补齐
	if(p<10&&y>=10)
	printf("0%d:%d",p,y);
	else if(p<10&&y<10)
	printf("0%d:0%d",p,y);
	else if(p>=10&&y<10)
	printf("%d:0%d",p,y);
	else
	printf("%d:%d",p,y);
}

2. Stones

Title description:

Alice and Bob have played with stones together since they were young.
One day, they wanted to play a pebble game happily.
There are a total of n piles of stones, the i-th pile of stones has ai, and the two take turns to operate.
Alice takes the lead. Each person can only operate on one pile of stones per round. Alice can only take an even number of stones per operation, and Bob can only take an odd number of stones per operation, and take at least one stone per operation until One party cannot perform any operations, and the inoperable person fails.
Assuming that Alice and Bob are both extremely smart, if Alice can win, then output YES, otherwise output NO.

Input format

Multiple sets of data. For each set of data, enter a positive integer n in the first line, enter n positive integers in the second line, and the i-th number represents ai.

Output format

For each group of data, a string YES or NO is output per line.

Sample input 1:
2
2 1
Sample output 1:
NO
Sample input 2:
1
6
Sample output 2:
YES
answer:

As long as Bob, every time he takes even-numbered piles, he takes away odd-numbered piles so that all piles become odd-numbered piles.

Because Alice can only take an even number at a time, there must be one stone left in each pile.

That's it

There is also a special case: as long as one pile and that pile is an even pile so that Alice can take him directly, Bob cannot operate it.

Also remember that there are multiple sets of data.

On the code:

#include<bits/stdc++.h>
using namespace std;
int a[1000005];
int main()
{
    
    
	int n;
	while(scanf("%d",&n)!=EOF)
	{
    
    
		for(int i=1;i<=n;i++)
		{
    
    
			scanf("%d",&a[i]);
		}
		if(n==1&&a[1]%2==0)  //判断那个特殊的情况
		{
    
    
			printf("YES\n");
		}
		else
		{
    
    
			printf("NO\n");
		}
	}
}
3. Card
Title description:

Alice and Bob each bring a regular polygon card.
Alice's card is a regular m-sided polygon with side length a, and Bob's card is a regular n-sided polygon with side length b.
Alice and Bob put two cards together. The two cards do not overlap and have at least one common vertex and one common edge.
Alice likes to rotate, so she rotates her polygon clockwise along Bob's card.
The center point of the rotation is a point on the common edge of the polygon, and the two cards do not overlap during the rotation.
Alice wants to know how many rotations, Alice's regular polygon will return to its original position.

Input format:

One line, four integers a, m, b, n, meaning as described in the title description.

Output format:

One line, one number Ans, represents the number of times Alice rotates.

Input example 1:
2 4 3 4
Output sample 1:
8

Picture explanation of the first two operations of the first example

Input example 2:
3 4 4 4
Output sample 2:
24
Input sample 3:
2020 1024 2021 1025
Output sample 3:
828200
answer:

Write gcd first ⁡ \gcdg cd andlcm ⁡ \operatorname{lcm}l c m . (Note the use of long long)

The first step is to find the length of Alice's card to roll on Bob's ball, x = lcm (a, b × n) x=lcm(a\ ,\ b\times n)x=lcm(a , b×n)

Because you want to go to the original position, lcm lcm is requiredlcm

The second step is to find the number of vertices to go back to the original position, y = lcm (a, b × n) ÷ by=lcm(a\ ,\ b\times n)\div bY=lcm(a,  b×n)÷b

The third step is to find how many times the points of the two polygons overlap during the rotation t = lcm (a, b) / bt=lcm(a,b)/bt=lcm(a,b)/b

The final result is x / a + y − y / tx/a+yy/tx/a+Yy/t

#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL gcd(LL a,LL b)
{
    
    
	if(b==0)return a;
	return gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
    
    
	return a*b/gcd(a,b);
}
int main()
{
    
    
	LL a,m,b,n;
	scanf("%lld%lld%lld%lld",&a,&m,&b,&n);
	LL t=lcm(a,b)/b;
	LL x=lcm(a,b*n);
	LL y=x/b;
	printf("%lld\n",x/a+y-y/t);
}

4. Necklace

No more

Thanks for watching

Guess you like

Origin blog.csdn.net/weixin_50773864/article/details/109313993