CF1584

A Mathematical Addition

容易推出\(-\frac{v^2}{u^2}=\frac{x}{y}\)所以\(x=-v^2\) \(y=u^2\)

#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 u,v;
		cin>>u>>v;
		cout<<-(u*u)<<" "<<v*v<<'\n';
	} 
	return 0;
}

B Coloring Rectangles

又不会B题...
考虑假如切割成三个时只染一次就行,这是最优的,四个要染两次,两个要染一次,所以尽量把所有的都分成1*3的就行了

#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,m;
		cin>>n>>m;
		cout<<(n*m+2)/3<<'\n'; 
	}
	return 0;
}

C Two Arrays

直接将两数组排序然后看对应的\(b_i\)是不是比\(a_i\)大零或一就行了

#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
int a[maxn];
int b[maxn];
signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		for(int i=1;i<=n;i++){
			cin>>b[i];
		}
		bool flag=0;
		sort(a+1,a+1+n);
		sort(b+1,b+1+n);
		for(int i=1;i<=n;i++){
			if(a[i]==b[i]||a[i]==b[i]-1) continue;
			else flag=1;
		}
		if(flag) cout<<"NO"<<'\n';
		else cout<<"YES"<<'\n';
	}
	return 0;
}

D Guess the Permutation

看到题面后很容易想到要先二分找到翻转区间的左端点,但是复杂度不允许再去二分剩下的两个端点,很容易想到一个递减区间内最大的数的逆序对个数就是该区间的长度,所以剩下两个端点就很好找了询问起始点和起始点+1就行

#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
bool check(int mid){
	cout<<"? "<<1<<" "<<mid<<endl;
	int num;
	cin>>num;
	if(num==0) return 1;
	else return 0;
}
signed main(){
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int st=0;
		int l=1,r=n;
		while(l<=r){
			int mid=l+r>>1;
			if(check(mid)) l=mid+1;
			else r=mid-1;
		}
		st=r;
		cout<<"? "<<st<<" "<<n<<endl;
		int now1,now2;
		cin>>now1;
		cout<<"? "<<st+1<<" "<<n<<endl;
		cin>>now2;
		int len1=now1-now2;
		int st2=st+len1+1;
		cout<<"? "<<st2<<" "<<n<<endl;
		int now3,now4;
		cin>>now3;
		cout<<"? "<<st2+1<<" "<<n<<endl;
		cin>>now4;
		int len2=now3-now4;
		cout<<"! ";
		cout<<st<<" "<<st2<<" "<<st2+len2<<endl; 
	} 
	return 0;
}

posted @ 2023-10-31 19:23  jt0007  阅读(176)  评论(0编辑  收藏  举报