自学内容网 自学内容网

Codeforces Round 931 (Div. 2)

A.

贪心,排序最大减去最小,第二大减去第二小

// Problem: A. Too Min Too Max
// Contest: Codeforces - Codeforces Round 931 (Div. 2)
// URL: https://codeforces.com/contest/1934/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//  /l、
// (゚、 。 7
//  l、 ~ヽ
//  じしf_, )ノ
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
ll a[N];
void Lan(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+1+n);
cout<<abs(a[1]-a[n-1])+abs(a[n-1]-a[2])+abs(a[2]-a[n])+abs(a[n]-a[1])<<'\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}

B.

最小公倍数是30

暴力

// Problem: B. Yet Another Coin Problem
// Contest: Codeforces - Codeforces Round 931 (Div. 2)
// URL: https://codeforces.com/contest/1934/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//  /l、
// (゚、 。 7
//  l、 ~ヽ
//  じしf_, )ノ
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
void Lan(){
int n;
cin>>n;
int ans=n;
//最小公倍数 30
for(int i=0;i<3;i++){// 1,2(1)
for(int j=0;j<2;j++){//3(3)
for(int k=0;k<5;k++){//6,12,18,24(6)
for(int l=0;l<3;l++){//10,20(10)
int rem=n-i-j*3-k*6-l*10;//优化一层枚举15
if(rem%15==0 && rem>=0){
ans=min(ans,i+j+k+l+(rem/15));
}
}
}
}
}
cout<<ans<<'\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}

C.

找三个角,存在两个交点

再询问一个交点

// Problem: C. Find a Mine
// Contest: Codeforces - Codeforces Round 931 (Div. 2)
// URL: https://codeforces.com/contest/1934/problem/C#
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//  /l、
// (゚、 。 7
//  l、 ~ヽ
//  じしf_, )ノ
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
void Lan(){
int n,m;
cin>>n>>m;
//询问3个角
//2个交点必然存在一个,再询问一个交点
int res1,res2,res3;
cout<<"?"<<" "<<1<<" "<<1<<endl;
cin>>res1;
cout<<"?"<<" "<<n<<" "<<1<<endl;
cin>>res2;
cout<<"?"<<" "<<n<<" "<<m<<endl;
cin>>res3;
int y1=(res1+res2+3-n)/2,x1=res1+2-y1;
int x2=(2*n+m-1-res2-res3)/2,y2=res2+1-n+x2;
if(x1<=0 || x1>n || y1<=0 || y1>m){//询问越界
cout<<"!"<<" "<<x2<<" "<<y2<<endl;
}else{
cout<<"?"<<" "<<x1<<" "<<y1<<endl;
int t;
cin>>t;
if(t==0){
cout<<"!"<<" "<<x1<<" "<<y1<<endl;
}else{
cout<<"!"<<" "<<x2<<" "<<y2<<endl;
}
}


}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}


原文地址:https://blog.csdn.net/Lanthamum/article/details/136414942

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!