Codeforces Round #639 (Div. 2)日常训练

A. Puzzle Pieces

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given a special jigsaw puzzle consisting of n⋅m identical pieces. Every piece has three tabs and one blank, as pictured below.

The jigsaw puzzle is considered solved if the following conditions hold:

The pieces are arranged into a grid with n rows and m columns.
For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.

Input
The test consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. Next t lines contain descriptions of test cases.

Each test case contains two integers n and m (1≤n,m≤105).

Output
For each test case output a single line containing “YES” if it is possible to solve the jigsaw puzzle, or “NO” otherwise. You can print each letter in any case (upper or lower).

Example
inputCopy
3
1 3
100000 100000
2 2
outputCopy
YES
NO
YES
Note
For the first test case, this is an example solution:

For the second test case, we can show that no solution exists.

For the third test case, this is an example solution:

#include<iostream>
using namespace std;
long long i,j,t,n,m;
bool f;
int main(){
	cin>>t;
	while(t--){
		cin>>n>>m;
		f=false;
		if(n==1 || m==1 || (n==m&&n==2)) f=true;
		if(f) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;		
	}
	return 0;
} 

B. Card Constructions

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
A card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of height h−1 onto a base. A base consists of h pyramids of height 1, and h−1 cards on top. For example, card pyramids of heights 1, 2, and 3 look as follows:

You start with n cards and build the tallest pyramid that you can. If there are some cards remaining, you build the tallest pyramid possible with the remaining cards. You repeat this process until it is impossible to build another pyramid. In the end, how many pyramids will you have constructed?

Input
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. Next t lines contain descriptions of test cases.

Each test case contains a single integer n (1≤n≤109) — the number of cards.

It is guaranteed that the sum of n over all test cases does not exceed 109.

Output
For each test case output a single integer — the number of pyramids you will have constructed in the end.

Example
inputCopy
5
3
14
15
24
1
outputCopy
1
2
1
3
0
Note
In the first test, you construct a pyramid of height 1 with 2 cards. There is 1 card remaining, which is not enough to build a pyramid.

In the second test, you build two pyramids, each of height 2, with no cards remaining.

In the third test, you build one pyramid of height 3, with no cards remaining.

In the fourth test, you build one pyramid of height 3 with 9 cards remaining. Then you build a pyramid of height 2 with 2 cards remaining. Then you build a final pyramid of height 1 with no cards remaining.

In the fifth test, one card is not enough to build any pyramids.

#include<iostream>
using namespace std;
long long t,i,j,k,m,n,ans;
long long a[200010];
int main(){
	cin>>t;
	a[1]=2;
	for(i=2;i<=200010;i++) a[i]=a[i-1]+3*i-1; 
	while(t--){
		cin>>m;
		if(m/2>200010)i=200009;
		else i=m/2;
		ans=0;
		while((i>0)&&(m>0)){
			if(a[i+1]>m && a[i]<=m){
				m=m-a[i];
				ans=ans+1;
				i=i+1;
			}
			i=i-1;
		}
		cout<<ans<<endl;
	}
	return 0;
}

------------分割线-------------

网断了,难受,其他题目只能再挑时候了。

C. Hilbert’s Hotel

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Hilbert’s Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel’s manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).

For any integer k and positive integer n, let kmodn denote the remainder when k is divided by n. More formally, r=kmodn is the smallest non-negative integer such that k−r is divisible by n. It always holds that 0≤kmodn≤n−1. For example, 100mod12=4 and (−1337)mod3=1.

Then the shuffling works as follows. There is an array of n integers a0,a1,…,an−1. Then for each integer k, the guest in room k is moved to room number k+akmodn.

After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.

Input
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. Next 2t lines contain descriptions of test cases.

The first line of each test case contains a single integer n (1≤n≤2⋅105) — the length of the array.

The second line of each test case contains n integers a0,a1,…,an−1 (−109≤ai≤109).

It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.

Output
For each test case, output a single line containing “YES” if there is exactly one guest assigned to each room after the shuffling process, or “NO” otherwise. You can print each letter in any case (upper or lower).

Example
inputCopy
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
outputCopy
YES
YES
YES
NO
NO
YES
Note
In the first test case, every guest is shifted by 14 rooms, so the assignment is still unique.

In the second test case, even guests move to the right by 1 room, and odd guests move to the left by 1 room. We can show that the assignment is still unique.

In the third test case, every fourth guest moves to the right by 1 room, and the other guests move to the right by 5 rooms. We can show that the assignment is still unique.

In the fourth test case, guests 0 and 1 are both assigned to room 3.

In the fifth test case, guests 1 and 2 are both assigned to room 2.

#include<cstring>
#include<iostream>
using namespace std;
long long t,i,j,m,n,f,k,ans;
long long a[200010],b[200010];
int main(){
	cin>>t;
	while(t--){
		cin>>n;
		f=0;
		memset(b,0,sizeof(b));
		for(i=0;i<n;i++){
			cin>>a[i];
		}
		for(i=0;i<n;i++){
			k=(i+(a[i]%n+n)%n)%n;
			if(b[k]==0)
				{
					b[k]=1;
				}
			else
				{
					f=1;
					break;
				}
		}
		if(f==0) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值