因为我只看了前三题而且都没有AC,我就光写ABC的题解吧还是。
A
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:
这个题没怎么明白题意。
AC代码
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
using namespace std;
int main()
{
int u; cin >> u;
while (u--)
{
int n, m; cin >> n >> m;
if (n == 1 || m == 1)
cout << "YES" << endl;
else
if (n == 2 && m == 2)
cout << "YES" << endl;
else cout << "NO" << endl;
}
}
B Card Constructions
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.
题意:就是用火柴去摆金字塔,找规律,给你n个火柴,每次摆必须得摆到最高的一个停下来去摆下一个,问你能摆几个金字塔。
这个规律想了好久才看出来 火柴数=(3hh+h)/2;
思路:这个题我怕超时就想把火柴数存到数组里,唉感觉自己想的太多了,直接暴力不行吗,又不会超时
气死了嘤嘤嘤
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
using namespace std;
#define inf 0x3f3f3f3f3f;
typedef long long ll;
int a[10000001];
int main()
{
int t; cin >> t;
while (t--)
{
int n; cin >> n;
int s = 0;
while (n >= 2)
{
while (n >= 2)
{
for (int i =2; i <=1000000000; i++)
{
int h1 = (3 * (i - 1) * (i - 1) + i - 1) / 2;
int h2 = (3 * i * i + i) / 2;
if (h1 <= n && h2 > n)
{
n -= h1;
s++;
break;
}
}
}
}
cout << s << endl;
}
}
C. Hilbert’s Hotel
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+ak mod n.
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
input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
output
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.
没读懂mod为负数的那一部分啊。。。