tozangezan's diary

勝手にソースコードをコピペして利用しないでください。

CodeRunner 2015 予選B

13位でなんとか通過しました。

基本的にちょっと残すか20000000くらい取る、安いのは捨てる、最後は回収する、固まったら仕方なく取りにいく、
さっさとコードを書いてぶん回す。

初心者からいくらふんだくって後半コンテストをいかに妨害するかみたいなコンテストで何か微妙だと思いました。ところでスコアシステム的にもデフレが起きるのはだいぶ予想がつくことです。

#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include<string.h>
#include<time.h>
using namespace std;
string query(string url) {
	FILE *f = popen(("curl-7.38.0-win64/bin/curl -s \"" + url + "\"").c_str(), "r");
	if (f == NULL) {
		perror("error!");
	}
	char buf[1024];
	string res;
	while (!feof(f)) {
		if (fgets(buf, 1024, f) == NULL) break;
		res += (string)(buf);
	}
	fclose(f);
	return res;
}
char add[100024];
double WaitTime=0.21;
double AtkTime = 1.0;
char in[100024];
int hp[20];
string token  = "これをオープンにすると本選のときに盗まれてしまいコンテスト終了";
void hit(){
	sprintf(add,"http://game.coderunner.jp/enter?token=%s",token.c_str());
	string to=add;
	string res=query(to);
	printf("%s\n",res.c_str());
}
int main() {
	
	srand(time(NULL));
	clock_t start=clock();
	clock_t atclock=clock()-CLOCKS_PER_SEC;
	int last=0;
	int SZ=1;
	//freopen("dat.txt","a",stdout);
	while(1){
		sprintf(add,"http://game.coderunner.jp/info?token=%s",token.c_str());
		string to=add;
		while((double)(clock()-start)/CLOCKS_PER_SEC<=WaitTime);
		string res=query(to);
		start=clock();
		sprintf(in,"%s",res.c_str());
		if(in[0]=='O'){
			hit();
			atclock=clock();
			continue;
		}
		FILE *fp=fopen("tmp.txt","w");
		fprintf(fp,"%s",in);
		fclose(fp);
		fp=fopen("tmp.txt","r");
		for(int i=0;i<20;i++)hp[i]=0;
		int nowatt,tot,n,fhp;
		fscanf(fp,"%d%d%d%d%d",&nowatt,&tot,hp,&fhp,&n);
		for(int i=0;i<n;i++)fscanf(fp,"%d",hp+1+i);
		n++;
		fclose(fp);
		for(int i=0;i<30;i++)printf("\n");
		printf("%d %d %d %d %d\n",hp[0]-nowatt,hp[0],hp[1],hp[2],tot);
		
		if(hp[0]==0||((hp[0]-nowatt>0||hp[0]>7000000)&&(nowatt>10000000||nowatt>hp[0])&&(hp[0]-nowatt<max(1000000,fhp/5)||min(nowatt,hp[0])>20000000)&&(double)(clock()-atclock)/CLOCKS_PER_SEC>=AtkTime)){
			hit();
			atclock=clock();
		}else if(n==1&&nowatt>=hp[0]&&(double)(clock()-atclock)/CLOCKS_PER_SEC>=0.51){
			hit();
			atclock=clock();
		}
	}
	return 0;
}