目录
Average Height
题意: n个数排序,尽可能多的使得 相邻两个数的平均数是整数;
题解:即只需奇数排在一起,偶数排在一起~
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100010;
int a[2020];
int b[2020];
int main() {
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--) {
int n;
cin>>n;
int l=0,r=n;
for(int i=1; i<=n; i++) {
cin>>a[i];
if(a[i]%2)
b[++l]=a[i];
else b[r--]=a[i];
}
for(int i=1; i<=n; i++)
cout<<b[i]<<" ";
cout<<endl;
}
return 0;
}
Review Site
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100010;
int a[2020];
int main() {
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--) {
int n;
cin>>n;
int maxx=0;
for(int i=1; i<=n; i++) {
cin>>a[i];
if(a[i]==1||a[i]==3)
maxx++;
}
cout<<maxx<<endl;
}
return 0;
}
Red and Blue Beans
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100010;
int main() {
int t;
cin>>t;
while(t--) {
int r,b,d;
cin>>r>>b>>d;
int minn=0,maxx=0;
if(r<b) minn=r, maxx=b;
else minn=b,maxx=r;
if(d==0) {
if(r==b)
cout<<"YES"<<endl;
else cout<<"NO"<<endl;
} else {
///分成minn堆,设颜色为 r,则每堆中有r、b颜色各一个
///(maxx-minn)/minn向上取整就是(maxx-1)/minn
///若满足|number(r)-number(b)|<=d --YES
if((maxx-1)/minn<=d)
cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
return 0;
}
TMT Document
题意:一个长度为n的字符串,如果可以构成n/3个“TMT”子序列~ 输出YES,
分析:首先M个数的二倍要等于T的个数;1.从前往后扫一遍, M左边 T的数量要>M的数量 2.从后往前扫 M右边 T的数量要>M的数量 都满足输出YES
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool check(int n,string s) {
int m=0,t=0;/// the number of M 、 T
int flag=0;
for(int i=0; i<n; i++) {
if(s[i]=='M') {
m++;
} else t++;
if(t<m)return false;
}
if(2*m!=t)return false;
m=0,t=0;
for(int i=n-1; i>=0; i--) {
if(s[i]=='M')
m++;
else t++;
if(t<m)
return false;
}
return true;
}
int main() {
int t;
cin>>t;
while(t--) {
int n;
cin>>n;
string s;
cin>>s;
if(!check(n,s))cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return 0;
}
GCD Length
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100010;
///input a、b、c 分别表示无前导零的a位、b位、c位数
///output gcd(a,b)=c
//输出a和b...仔细看输出,不要在这上面交罚时,血亏..
int main() {
int t;
cin>>t;
while(t--) {
ll a,b,c;
cin>>a>>b>>c;
ll k=b-c,k2=a-c;
ll s3=0,s2=0,s1=0;
while(c--)s3=s3*10+1;///
s2=s3,s1=s3;
while(k--)s2*=13;///保证位数符合题意
while(k2--) s1*=11;///且保证gcd(s1,s2)=s3
//因为11 13互质 ..
cout<<s1<<" "<<s2<<endl;
// cout<<"++"<<__gcd(s1,s2)<<endl;
}
return 0;
}
The Cake Is a Lie
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100010;
///从(1,1)~(n,m) 总消耗==k,则输出yes
///(x,y)-->(x,y+1) cost x
///(x,y)-->(x+1,y) cost y
///两种路线 先(1,1)~(n,1) cost (n-1)*y=n-1;
// 后~(n,m) cost (m-1)*n
/// 先(1,1)~(1,m) cost (m-1)*x=m-1;
// 后~(n,m) cost (n-1)*m
int main() {
int t;
cin>>t;
while(t--) {
int n,m,k;
cin>>n>>m>>k;
if(n*m-1==k)
cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}