2019 Petrozavodsk Winter Camp, Yandex Cup 解题报告

H


签到题,每行最小值的最大值就是答案。


#include <bits/stdc++.h>

using namespace std;

#define ll long long
ll input(){
	ll x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

int n;
ll Ans,tmp;

int main(){
	n=input();
	for(int i=1;i<=n;i++){
		tmp=0x3f3f3f3f;
		for(int j=1;j<=n;j++)
			tmp=min(tmp,input());
		Ans=max(tmp,Ans);
	}
	printf("%lld\n",Ans);
}

A


贪心,每次选择增量最小的点。


#include <bits/stdc++.h>

using namespace std;

#define ll long long
ll input(){
	ll x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

#define PII pair<int,int>
#define fr first
#define sc second
#define mp make_pair

const int N=3e5+7;

struct node{
	int x,y;
	int id;
	bool operator <(const node &t)const{
		return x+y>t.x+t.y;
	}
}a[N];

int n;

priority_queue <node> Q;

int main(){
	n=input();
	for(int i=1;i<=n;i++){
		a[i].x=input(),a[i].y=input();
		a[i].id=i;
		Q.push(a[i]);
	}

	int x=1,y=1;

	while(!Q.empty()){
		node t=Q.top();Q.pop();
		if(x>t.x){
			t.x=x;
			Q.push(t);
			continue;
		}
		if(y>t.y){
			t.y=y;
			Q.push(t);
			continue;
		}

		printf("%d%c",t.id,Q.empty()? '\n':' ');
		x=max(x,t.x),y=max(t.y,y);
	}
}

J


往左右试探,每次倍增4倍(因为要在30m内解决问题)当走到1时分别执行一次+和-,就很简单的知道答案是什么了。


#include <bits/stdc++.h>

using namespace std;

#define ll long long
ll input(){
	ll x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

int main(){
	char c='+';
	int len=1,check;
	while(1){
		for(int i=1;i<=len;i++){
			cout<<c<<endl;
			cin>>check;
			if(check){
				cout<<'+'<<endl;
				cin>>check;
				cout<<'-'<<endl;
				cin>>check;
				if(check) cout<<"! ugly"<<endl;
				else if(c=='+') cout<<"! bad"<<endl;
				else cout<<"! good"<<endl;
				return 0;
			}
		}
		c='+'+'-'-c;
		len*=4;
	}
}

猜你喜欢

转载自www.cnblogs.com/-aether/p/12715693.html