Codeforces Round 1014 (Div. 2)
A. Kamilka and the Sheep
不妨设x<=y,两个数gcd小于这两个数
gcd(x+d,y+d)<=x+d<=y+d是我们常常知道的
也<=y-x
x+d=k1(y-x)
y+d=k2(y-x)
y-x=(k2-k1)(y-x)
只要k2-k1=1,就可以任意d
所以可达y-x
就是找y-x最大
#include<iostream>
using namespace std;
#define ll long long
#include<algorithm>
ll a[110];
int n;
int main(){
int T;cin>>T;
while(T--){
cin>>n;
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
sort(a+1,a+n+1);
cout<<a[n]-a[1]<<endl;
/* for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i!=j){
if(a[j]>=2*a[i]){
ans=max(ans,a[i]+a[j]-2*a[i]);
}
}
}
}*/
//cout<<ans<<endl;
}
}
B. Lady Bug
发现也就两条路径,
正的彼此之间可以任意通过交换排序,反的彼此之间可以通过交换排成任意顺序
只要正的和反的都能凑够要求的数即可
#include<iostream>
using namespace std;
int n;string a,b;
int main(){
int T;cin>>T;
while(T--){
cin>>n>>a>>b;
int cnt0=0;int cnt1=0;
for(int i=0;i<n;i++){
if(a[i]=='0'){
if(i&1)cnt0++;
else cnt1++;
}
}
for(int i=0;i<n;i++){
if(b[i]=='0'){
if(i&1)cnt1++;
else cnt0++;
}
}
/*
if(cnt0>=(n+1)/2&&cnt1>=n/2){
cout<<"YES\n";
}else
*/
if(cnt0>=n/2&&cnt1>=(n+1)/2){
cout<<"YES\n";
}else {
cout<<"NO\n";
}
}
}
C. Asuna and the Mosquitoes
可以吸收掉,成为奇数中剩一个把所有的吸收掉的,和其他奇数变成1
偶数都能吸收掉
#include<iostream>
using namespace std;
#include<algorithm>
#define ll long long
ll a[200010];
ll n;
int main(){
ll T;cin>>T;
while(T--){
cin>>n;ll cnt1=0;ll cnt0=0;ll sum=0;
for(ll i=1;i<=n;i++){scanf("%lld",&a[i]);
if(a[i]&1)cnt1++;else cnt0++;
sum+=a[i];
}
sort(a+1,a+n+1);
if(cnt1==0){
cout<<a[n]<<endl;
continue;
}
if(cnt0==0){
cout<<a[n]<<endl;continue;
}
cout<<sum-(cnt1-1)<<endl;
}
}
D. Mishkin Energizer
n非常小,每次暴力模拟,
为什么会tle啊啊啊
E. She knows...




至于怎么处理在棱边上的
1)没有全填满,先填其他的,剩下一个方案唯一,2^(n*m-k-1)
2)全填满了,由于其他格子怎么填都不影响奇偶性,不妨全都填白的,
那就转化为黑色格子的个数的奇偶性,如果奇数0,偶数其他随便填
#include<iostream>
using namespace std;
#define ll long long
const ll mod=1e9+7;
ll n,m,k;
ll ksm(ll a,ll b){
ll res=1;
while(b){
if(b&1)res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
int main(){
ll T;cin>>T;
while(T--){
cin>>n>>m>>k;ll z=0;ll cnt1=0;
for(ll i=1;i<=k;i++){
ll x,y,c;
cin>>x>>y>>c;
if(x==1||y==1||x==n||y==m){
if(x==1&&y==1);
else if(x==1&&y==m);
else if(x==n&&y==1);
else if(x==n&&y==m);
else {
z++;if(c==1)cnt1++;
}
}
}
// cout<<"ok1"<<endl;
//cout<<z<<" "<< 2*n+2*m-8<<" "<<cnt1<<endl;
if(z==2*n+2*m-8){
if(cnt1&1){
cout<<0<<endl;
}else cout<<ksm(2,n*m-k)<<endl;
}
else cout<<ksm(2,n*m-k-1)<<endl;
}
}

浙公网安备 33010602011771号