Submission #45829

# Submission time Handle Problem Language Result Execution time Memory
45829 2018-04-16T08:34:43 Z mraron Go, Gopher! (GCJ18Q_gogopher) C++14
30 / 30
73 ms 436 KB
//Noszály Áron 10o Debreceni Fazekas Mihály Gimnázium

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define FORN(i, n) for(int i=0;i<(n);i++)
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, l, r) for ((i) = (l); (i) < (r); (i)++)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

bool digged[20][20];

int d[9][2]={{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}, {0,0}};

int main() {
	IO;
	int T;
	cin>>T;
	while(T--) {
		int meret;
		cin>>meret;
		int oldal=ceil(sqrt(meret));
		
		memset(digged, 0, sizeof digged);
		
		int digged_cnt=0;
		while(digged_cnt<=oldal*oldal) {
			int minval=111;
			pair<int,int> koord;
			for(int i=3;i<=oldal;++i) {
				for(int j=3;j<=oldal;++j) {
					int cnt=0;
					for(auto k:d) {
						int ni=i+k[0], nj=j+k[1];
						cnt+=digged[ni][nj];
					}
					if(cnt<minval) {
						minval=cnt;
						koord={i,j};
					}
				}
			}
			
			cout<<koord.xx<<" "<<koord.yy<<"\n";cout.flush();
			//cerr<<koord.xx<<" "<<koord.yy<<" "<<(oldal*oldal-digged_cnt)<<" "<<minval<<" "<<meret<<"\n";cerr.flush();
			/*for(int i=2;i<=oldal+1;++i) {
				for(int j=2;j<=oldal+1;++j) {	
					cerr<<digged[i][j]<<" ";
				}cerr<<"\n";
			}*/
			int a,b;
			cin>>a>>b;
			//cerr<<a<<" "<<b<<"\n";
			if(a==-1) return 0;
			if(a==0) break ;
			if(!digged[a][b]) digged_cnt++;
			digged[a][b]=true;
 		}
		
	}
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 8 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 436 KB Output is correct