A Distance
直接枚举C点x坐标暴力判断
#include<bits/stdc++.h>
using namespace std;
int xa,ya,xb,yb;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
cin>>xb>>yb;
int tot=xb+yb;
if(tot%2!=0){
cout<<"-1"<<" "<<"-1"<<'\n';
continue;
}
for(int i=0;i<=tot/2;i++){
if(abs(xb-i)+abs(yb-(tot/2-i))==tot/2){
cout<<i<<" "<<tot/2-i<<'\n';
break;
}
}
}
return 0;
}
B Special Permutation
先判断不合法情况,如果小于等于a的数(不包括b)少于n/2个或者大于等于b的数(不包括a)少于你n/2个否则必然合法,那么对于前一半就从n开始输出,对于后一半就从1开始输出
#include<bits/stdc++.h>
using namespace std;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
int n,a,b;
cin>>n>>a>>b;
if(a>n/2+1){
cout<<"-1"<<'\n';
continue;
}
if(b<n/2){
cout<<"-1"<<'\n';
continue;
}
if(b==n/2&&a<b&&n!=2){
cout<<"-1"<<'\n';
continue;
}
if(a==n/2+1&&a<b&&n!=2){
cout<<"-1"<<'\n';
continue;
}
int cnt=0;
int now=n+1;
cout<<a<<" ";
while(cnt<n/2-1){
now--;
if(now==b) now--;
cout<<now<<" ";
cnt++;
}
cnt=0;
cout<<b<<" ";
now=0;
while(cnt<n/2-1){
now++;
if(now==a) now++;
cout<<now<<" ";
cnt++;
}
cout<<'\n';
}
return 0;
}
C Chat Ban
考虑二分答案然后用等差数列算一下就行
#include<bits/stdc++.h>
#define int long long
using namespace std;
int summ(int k,int now){
if(now==1) return 1;
if(now>k) return (k)*(k-1)/2+(k+k-(now-k))*(now-k+1)/2;
else return (now+1)*now/2;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
int k,x;
cin>>k>>x;
int l=1,r=k*2-1;
while(l<=r){
// if(t==4) cout<<l<<" "<<r<<'\n';
int mid=l+r>>1;
if(summ(k,mid)<x) l=mid+1;
else r=mid-1;
}
cout<<min(r+1,k*2-1)<<'\n';
}
return 0;
}
D X-Magic Pair
画一下图后可以发现没回用大的数减小的数出现的情况就可以覆盖所有情况,所以想到更相减损,然后就可以发现加入通过转化为b,x是否同余就可以取模加速
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
int a,b,x;
cin>>a>>b>>x;
bool flag=0;
if(a>b) swap(a,b);
while(a){
if(x%a==b%a&&x<=b){
flag=1;
cout<<"YES"<<'\n';
break;
}
b%=a;
if(a>b) swap(a,b);
}
if(!flag) cout<<"NO"<<'\n';
}
return 0;
}
标签:cout,int,cin,CF1612,while,tie,now
From: https://www.cnblogs.com/jt0007/p/17794235.html