题解:可以一起先凑齐最大的币值,能凑齐的话再看剩余的是否被 3 3 3整除即可。
c o d e : code: code:
#include
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
int a,b,c,n;
int main()
{
rush(){
sc2(a,b);sc2(c,n);
int maxx=max(a,max(b,c));
int cha=3*maxx-a-b-c;
if(n<cha)puts("NO");
else if((n-cha)%3!=0)puts("NO");
else puts("YES");
}
return 0;
}
题解:先按 x x x排序,再按 y y y排序,然后可以 n 2 n^2 n2判断下是否能全部采集,之后按照字典序先 R R R再 U U U即可。
c o d e : code: code:
#include
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
const int N=1e3+5;
int n;
pii dots[N];
void put(char c)
{
printf("%c",c);
}
int main()
{
rush(){
sc(n);
rep(i,0,n-1){
sc2(dots[i].fi,dots[i].se);
}
sort(dots,dots+n);
bool flag=true;
rep(i,0,n-2){
rep(j,i+1,n-1){
if(dots[i].se>dots[j].se){
flag=false;
break;
}
}
if(!flag)break;
}
if(!flag)puts("NO");
else{
puts("YES");
int r=0,u=0;
rep(i,0,n-1){
int nr=dots[i].fi,nu=dots[i].se;
rep(j,1,nr-r)put('R');
rep(j,1,nu-u)put('U');
r=nr,u=nu;
}
puts("");
}
}
return 0;
}
题解:可以用个因数枚举套个因数枚举即可。
c o d e : code: code:
#include
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
#define pf3(a,b,c) printf("%d %d %d\n",a,b,c)
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
int n,a,b,c,ab;
int main()
{
rush(){
sc(n);
bool flag=false;
rep(i,2,ceil(sqrt(n))){
if(n%i!=0)continue;
a=i,ab=n/a;
rep(j,2,ceil(sqrt(ab))){
if(ab%j!=0)continue;
b=j,c=ab/j;
if(a!=b&&a!=c&&b!=c&&a!=1&&b!=1&&c!=1){
flag=true;
break;
}
}
if(flag)break;
}
if(flag){
puts("YES");
pf3(a,b,c);
}
else{
puts("NO");
}
}
return 0;
}
题解:仔细发现一下可以看到其实和给出的数取模 x x x有关,那么可以用上几个标记,其一,记录此时的答案,其二,记录有了几排。
c o d e : code: code:
#include
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
const int N=4e5+5;
int q,x,y,now,tot,b[N],ans;
int main()
{
sc2(q,x);
int cnt=1;
rep(i,1,q){
sc(y);
int m=y%x;
b[m]++;
while(b[tot]>=cnt){
ans++;
tot++;
if(tot==x){
tot=0;
cnt++;
}
}
pf(ans);
}
return 0;
}
题解:第一次想到是用 n ∗ m × n n*m×n n∗m×n瞎搞, T T T到 8 8 8,在挖掘一番,可以直接将每个数应该 s h i f t shift shift多少下算出来作为贡献,然后每一列 s h i f t shift shift从 0 ∼ n − 1 0 \sim n-1 0∼n−1便可以用 O ( 1 ) O(1) O(1)统计出来,其中需要特判个这个数最后在哪一行需要特判,存在出界问题。
c o d e : code: code:
#include
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
const int N=2e5+5;
int n,m,c[N],sum,col,x;
vector<int>v[N];
int main()
{
sc2(n,m);
rep(i,1,n)rep(j,1,m)sc(x),v[j].pb(x);
rep(j,1,m){
rep(i,0,n-1)c[i]=0;
rep(i,1,n){
int u=v[j][i-1];
if(u%m==j%m){
int r=(u-j)/m+1;
if(r<0||r>n)continue;
int s=(i-r+n)%n;
c[s]++;
}
}
col=inf;
rep(i,0,n-1)col=min(col,n-c[i]+i);
sum+=col;
}
pf(sum);
return 0;
}
待补