A. Puzzle Pieces
显然如果边长大于 2 2 2之后一定含有 2 × 2 2×2 2×2的拼接块,而下面的拼接块显然不能再向周围扩展,因此只有1×?和2×2符合
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t,n,m;
cin>>t;
while(t--){
cin>>n>>m;
if(n==1 || m==1) puts("YES");
else if(n==2 && m==2) puts("YES");
else puts("NO");
}
return 0;
}
B. Card Constructions
找规律打表即可,因为序列是递增的,直接二分求上界减一即得到每次能构造的最大图形,循环求即可
这里写的时候又忘记了二分查找下标1开始的数组,也是直接减去数组首地址,而不需要减去首地址+1
PS:要打1e5表,使得最大值超过1e9
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;
const int N=1e5;
ll f[maxn];
void init(){
f[1]=2;
for(int i=2;i<=N;i++)
f[i]=f[i-1]+2*i+i-1;
//cout<<f[N]<<endl;
}
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,m,t;
cin>>t;
init();
while(t--){
cin>>n;
int ans=0;
while(n>=2){
int l=upper_bound(f+1,f+1+N,n)-f;
n-=f[l-1];
ans++;
}
cout<<ans<<endl;
}
return 0;
}
C. Hilbert’s Hotel
首先注意到这里的负数取模和计算机不同,计算机的 − 1337 % 3 = − 2 -1337\%3=-2 −1337%3=−2,但是这里 − 1337 % 3 -1337\%3 −1337%3等于 1 1 1。因为计算机处理时只考虑最小的 r r r使得 ( k − r ) ∣ n (k-r) | n (k−r)∣n,即 r = n − ( n / k ) x b r = n - (n / k) x b r=n−(n/k)xb,当我们取模后为负数时,将 n / k + 1 n/k+1 n/k+1即可得到最小的非负结果,即取模结果加上 n n n
图片来自Visors
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;
int a[maxn];
bool vis[maxn];
bool check(int n){
for(int i=0;i<n;i++)
if(!vis[i]) return false;
return true;
}
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t,n;
cin>>t;
while(t--){
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
memset(vis,0,sizeof vis);
for(int i=0;i<n;i++){
int cur=(i+a[i%n])%n;
if(cur<0) cur+=n;
vis[cur]=1;
}
if(check(n)) puts("YES");
else puts("NO");
}
return 0;
}