[挑战记录][POJ3760]魔兽世界(修改版)
20221005 16:30
开始答题
16:50
写了个初始化
17:31
假了,重构
17:53
基本重构完了(虽然一共也没写多少)
开始施工角色能力
17:59
\(100\) 行达成
然而又假了,重写
20:44
基本完成 \(\operatorname{step}\) 函数
21:24
开始构造 \(\operatorname{war}\) 函数
20221006 07:57
差不多搞完了,等着上午的考试
17:35
搞完了,开拍
等等,为啥网上四篇题解两两拍出来不一样???
找虎哥要了正解
20221007 06:39
拍了两千亿行
没拍出错
但它WA了
我不知道该说什么了
18:46
不能用 \(\operatorname{long~long}\) !!!
TMD把 \(\mathsf{ninja}\) 写成了 \(\mathsf{ninjn}\) 调了两天!!!
我宣布个事:我是 \(\operatorname{SB}\)
为什么会写错呢?
在第一次 \(WA\) 后
由于 \(\operatorname{std}\) 的输出和我的输出在行末有空格/回车区别,为了避免我用了 \(\operatorname{char}\)
然后手写了各种兵的名称,粘到了题解上
如图
name[1][0]='d',name[1][1]='r',name[1][2]='a',name[1][3]='g',name[1][4]='o',name[1][5]='n';
name[2][0]='n',name[2][1]='i',name[2][2]='n',name[2][3]='j',name[2][4]='a';
name[3][0]='i',name[3][1]='c',name[3][2]='e',name[3][3]='m',name[3][4]='a',name[3][5]='n';
name[4][0]='l',name[4][1]='i',name[4][2]='o',name[4][3]='n';
name[5][0]='w',name[5][1]='o',name[5][2]='l',name[5][3]='f';
由于第一次交的时候我已经过了样例我就没去管
拍了一晚上,两千亿行没出错
很好,很有趣
很有趣
最后再重复一遍:
我是 \(\operatorname{SB}\)
11kB码长,0ms
扔个数据生成器
生成器
#include<bits/stdc++.h>
#include<sys/time.h>
#include<unistd.h>
#define int long long
using namespace std;
int rand(int l,int r){
return l+(rand()%(r-l+1))*(rand()%(r-l+1))%(r-l+1);
}
signed main(){
struct timeval time;
gettimeofday(&time,0);
srand((unsigned int)time.tv_usec);
//这里写数据生成器
int T=rand(500,500);
printf("%lld\n",T);
while(T--){
printf("%lld %lld %lld\n",rand(100,200),rand(20,20),rand(990,1000)*10);
for(int i=1;i<=5;i++) printf("%lld ",rand(10,100));
printf("\n");
for(int i=1;i<=5;i++) printf("%lld ",rand(0,0));
printf("\n");
}
return 0;
}
下面是正解
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
#define WR WinterRain
using namespace std;
const int WR=100100;
struct Charactor{
int HP,atk;
}charactor[6];
struct Soldier{
int opt,atk,HP,pos,cnt,kill;
}rdsol[WR],blsol[WR];
struct City{
int flag,rdid,blid,ele;
int rdcnt,blcnt;
}city[WR];
struct Headquarter{
int ele,enemy[3],cnt,lzy;
vector<pair<int,int> >vic;
}hqrd,hqbl;
int m,n,t;
int posrd[6],posbl[6];
int totrd,totbl;
char name[10][101];
int read(){
int s=0,w=1;
char ch=getchar();
while(ch>'9'||ch<'0'){
if(ch=='-') w=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
s=(s<<1)+(s<<3)+ch-48;
ch=getchar();
}
return s*w;
}
void get_charactor(){
name[1][0]='d',name[1][1]='r',name[1][2]='a',name[1][3]='g',name[1][4]='o',name[1][5]='n';
name[2][0]='n',name[2][1]='i',name[2][2]='n',name[2][3]='j',name[2][4]='a';
name[3][0]='i',name[3][1]='c',name[3][2]='e',name[3][3]='m',name[3][4]='a',name[3][5]='n';
name[4][0]='l',name[4][1]='i',name[4][2]='o',name[4][3]='n';
name[5][0]='w',name[5][1]='o',name[5][2]='l',name[5][3]='f';
posrd[1]=3,posrd[2]=4,posrd[3]=5,posrd[4]=2,posrd[5]=1;
posbl[1]=4,posbl[2]=1,posbl[3]=2,posbl[4]=3,posbl[5]=5;
}
void prework(){
m=read(),n=read(),t=read();
totrd=totbl=0;
memset(hqrd.enemy,0,sizeof(hqrd.enemy));
memset(hqbl.enemy,0,sizeof(hqbl.enemy));
hqrd.ele=hqbl.ele=m;
hqrd.cnt=hqbl.cnt=0;
hqrd.lzy=hqbl.lzy=0;
for(int i=0;i<=n+1;i++){
city[i].flag=city[i].ele=0;
city[i].rdid=city[i].blid=0;
city[i].rdcnt=city[i].blcnt=0;
}
for(int i=1;i<=5;i++) charactor[i].HP=read();
for(int i=1;i<=5;i++) charactor[i].atk=read();
}
bool judge_win(pair<int,int>tme){
if(hqrd.cnt==2||hqbl.cnt==2) return true;
return false;
}
void get_birth_red(pair<int,int>tme){
int pos=totrd%5+1;
if(hqrd.ele<charactor[posrd[pos]].HP) return;
hqrd.ele-=charactor[posrd[pos]].HP;
printf("%03d:%02d ",tme.first,tme.second);
printf("red %s",name[posrd[pos]]);
printf(" %d born\n",++totrd);
city[0].rdid=totrd;
rdsol[totrd].opt=posrd[pos];
rdsol[totrd].atk=charactor[posrd[pos]].atk;
rdsol[totrd].HP=charactor[posrd[pos]].HP;
rdsol[totrd].pos=0;
rdsol[totrd].kill=rdsol[totrd].cnt=0;
}
void get_birth_blue(pair<int,int>tme){
int pos=totbl%5+1;
if(hqbl.ele<charactor[posbl[pos]].HP) return;
hqbl.ele-=charactor[posbl[pos]].HP;
printf("%03d:%02d ",tme.first,tme.second);
printf("blue %s",name[posbl[pos]]);
printf(" %d born\n",++totbl);
city[n+1].blid=totbl;
blsol[totbl].opt=posbl[pos];
blsol[totbl].atk=charactor[posbl[pos]].atk;
blsol[totbl].HP=charactor[posbl[pos]].HP;
blsol[totbl].pos=n+1;
blsol[totbl].kill=blsol[totbl].cnt=0;
}
void get_birth(pair<int,int>tme){
get_birth_red(tme);
get_birth_blue(tme);
}
void red_iceman(int id){
if(rdsol[id].cnt&&rdsol[id].cnt%2==0){
rdsol[id].HP-=9;
if(rdsol[id].HP<=0) rdsol[id].HP=1;
rdsol[id].atk+=20;
}
}
void blue_iceman(int id){
if(blsol[id].cnt&&blsol[id].cnt%2==0){
blsol[id].HP-=9;
if(blsol[id].HP<=0) blsol[id].HP=1;
blsol[id].atk+=20;
}
}
void march_red(pair<int,int>tme,int id){
printf("%03d:%02d ",tme.first,tme.second);
printf("red %s %d",name[rdsol[id].opt],id);
if(rdsol[id].opt==3) red_iceman(id);
}
void march_blue(pair<int,int>tme,int id){
printf("%03d:%02d ",tme.first,tme.second);
printf("blue %s %d",name[blsol[id].opt],id);
if(blsol[id].opt==3) blue_iceman(id);
}
void step(pair<int,int>tme){
for(int i=1;i<=n+1;i++){
if(city[i].blid){
city[i-1].blid=city[i].blid;
blsol[city[i-1].blid].cnt++;
city[i].blid=0;
}
}
for(int i=n;i>=0;i--){
if(city[i].rdid){
city[i+1].rdid=city[i].rdid;
rdsol[city[i+1].rdid].cnt++;
city[i].rdid=0;
}
}
if(city[0].blid!=hqrd.enemy[hqrd.cnt]){
int id=city[0].blid;
march_blue(tme,id);
printf(" reached red headquarter with %d elements and force %d\n",blsol[id].HP,blsol[id].atk);
hqrd.enemy[++hqrd.cnt]=city[0].blid;
if(hqrd.cnt==2) printf("%03d:%02d red headquarter was taken\n",tme.first,tme.second);
}
for(int i=1;i<=n;i++){
if(city[i].rdid){
int id=city[i].rdid;
march_red(tme,id);
printf(" marched to city %d with %d elements and force %d\n",i,rdsol[id].HP,rdsol[id].atk);
}
if(city[i].blid){
int id=city[i].blid;
march_blue(tme,id);
printf(" marched to city %d with %d elements and force %d\n",i,blsol[id].HP,blsol[id].atk);
}
}
if(city[n+1].rdid!=hqbl.enemy[hqbl.cnt]){
int id=city[n+1].rdid;
march_red(tme,id);
printf(" reached blue headquarter with %d elements and force %d\n",rdsol[id].HP,rdsol[id].atk);
hqbl.enemy[++hqbl.cnt]=city[n+1].rdid;
if(hqbl.cnt==2) printf("%03d:%02d blue headquarter was taken\n",tme.first,tme.second);
}
}
void spawn(){
for(int i=1;i<=n;i++) city[i].ele+=10;
}
bool red_cmp(pair<int,int>x,pair<int,int>y){
return x.first>y.first;
}
bool blue_cmp(pair<int,int>x,pair<int,int>y){
return x.first<y.first;
}
void red_get_element(pair<int,int>tme,int id,int pos){
printf("%03d:%02d ",tme.first,tme.second);
printf("red %s",name[rdsol[id].opt]);
printf(" %d earned %d elements for his headquarter\n",id,city[pos].ele);
hqrd.lzy+=city[pos].ele,city[pos].ele=0;
}
void blue_get_element(pair<int,int>tme,int id,int pos){
printf("%03d:%02d ",tme.first,tme.second);
printf("blue %s",name[blsol[id].opt]);
printf(" %d earned %d elements for his headquarter\n",id,city[pos].ele);
hqbl.lzy+=city[pos].ele,city[pos].ele=0;
}
void get_elements(pair<int,int>tme){
for(int i=1;i<=n;i++){
if(city[i].rdid&&(!city[i].blid)) red_get_element(tme,city[i].rdid,i);
if((!city[i].rdid)&&city[i].blid) blue_get_element(tme,city[i].blid,i);
}
}
void get_lazy(){
hqrd.ele+=hqrd.lzy,hqrd.lzy=0;
hqbl.ele+=hqbl.lzy,hqbl.lzy=0;
}
void war_clr(){
hqrd.vic.clear();
hqbl.vic.clear();
}
void red_dragon(pair<int,int>tme,int id,int pos){
printf("%03d:%02d ",tme.first,tme.second);
printf("red dragon %d yelled in city %d\n",id,pos);
}
void blue_dragon(pair<int,int>tme,int id,int pos){
printf("%03d:%02d ",tme.first,tme.second);
printf("blue dragon %d yelled in city %d\n",id,pos);
}
void red_active_kill(pair<int,int>tme,int idrd,int idbl,int pos){
printf("%03d:%02d ",tme.first,tme.second);
printf("red %s",name[rdsol[idrd].opt]);
printf(" %d attacked ",idrd);
printf("blue %s",name[blsol[idbl].opt]);
printf(" %d in city %d with %d elements and force %d\n",idbl,pos,rdsol[idrd].HP,rdsol[idrd].atk);
blsol[idbl].HP-=rdsol[idrd].atk;
if(blsol[idbl].HP<=0){
printf("%03d:%02d ",tme.first,tme.second);
printf("blue %s",name[blsol[idbl].opt]);
printf(" %d was killed in city %d\n",idbl,pos);
rdsol[idrd].kill++;
if(rdsol[idrd].opt==5&&rdsol[idrd].kill%2==0) rdsol[idrd].HP*=2;
if(blsol[idbl].opt==4) rdsol[idrd].HP+=blsol[idbl].HP+rdsol[idrd].atk;
if(rdsol[idrd].opt==5&&rdsol[idrd].kill%2==0) rdsol[idrd].atk*=2;
hqrd.vic.push_back(make_pair(pos,idrd));
city[pos].blcnt=0,city[pos].rdcnt++;
city[pos].blid=0;
}else if(blsol[idbl].opt==2) city[pos].blcnt=city[pos].rdcnt=0;
}
void blue_active_kill(pair<int,int>tme,int idrd,int idbl,int pos){
printf("%03d:%02d ",tme.first,tme.second);
printf("blue %s",name[blsol[idbl].opt]);
printf(" %d attacked ",idbl);
printf("red %s",name[rdsol[idrd].opt]);
printf(" %d in city %d with %d elements and force %d\n",idrd,pos,blsol[idbl].HP,blsol[idbl].atk);
rdsol[idrd].HP-=blsol[idbl].atk;
if(rdsol[idrd].HP<=0){
printf("%03d:%02d ",tme.first,tme.second);
printf("red %s",name[rdsol[idrd].opt]);
printf(" %d was killed in city %d\n",idrd,pos);
blsol[idbl].kill++;
if(blsol[idbl].opt==5&&blsol[idbl].kill%2==0) blsol[idbl].HP*=2;
if(rdsol[idrd].opt==4) blsol[idbl].HP+=rdsol[idrd].HP+blsol[idbl].atk;
if(blsol[idbl].opt==5&&blsol[idbl].kill%2==0) blsol[idbl].atk*=2;
hqbl.vic.push_back(make_pair(pos,idbl));
city[pos].rdcnt=0,city[pos].blcnt++;
city[pos].rdid=0;
}else if(rdsol[idrd].opt==2) city[pos].blcnt=city[pos].rdcnt=0;
}
void red_passive_kill(pair<int,int>tme,int idrd,int idbl,int pos){
printf("%03d:%02d ",tme.first,tme.second);
printf("red %s",name[rdsol[idrd].opt]);
printf(" %d fought back against ",idrd);
printf("blue %s",name[blsol[idbl].opt]);
printf(" %d in city %d\n",idbl,pos);
blsol[idbl].HP-=(rdsol[idrd].atk>>1);
if(blsol[idbl].HP<=0){
printf("%03d:%02d ",tme.first,tme.second);
printf("blue %s",name[blsol[idbl].opt]);
printf(" %d was killed in city %d\n",idbl,pos);
if(blsol[idbl].opt==4) rdsol[idrd].HP+=blsol[idbl].HP+(rdsol[idrd].atk>>1);
hqrd.vic.push_back(make_pair(pos,idrd));
city[pos].blcnt=0,city[pos].rdcnt++;
city[pos].blid=0;
}else city[pos].blcnt=city[pos].rdcnt=0;
}
void blue_passive_kill(pair<int,int>tme,int idrd,int idbl,int pos){
printf("%03d:%02d ",tme.first,tme.second);
printf("blue %s",name[blsol[idbl].opt]);
printf(" %d fought back against ",idbl);
printf("red %s",name[rdsol[idrd].opt]);
printf(" %d in city %d\n",idrd,pos);
rdsol[idrd].HP-=(blsol[idbl].atk>>1);
if(rdsol[idrd].HP<=0){
printf("%03d:%02d ",tme.first,tme.second);
printf("red %s",name[rdsol[idrd].opt]);
printf(" %d was killed in city %d\n",idrd,pos);
if(rdsol[idrd].opt==4) blsol[idbl].HP+=rdsol[idrd].HP+(blsol[idbl].atk>>1);
hqbl.vic.push_back(make_pair(pos,idbl));
city[pos].rdcnt=0,city[pos].blcnt++;
city[pos].rdid=0;
}else city[pos].blcnt=city[pos].rdcnt=0;
}
void red_flag(pair<int,int>tme,int pos){
city[pos].flag=1;
printf("%03d:%02d ",tme.first,tme.second);
printf("red flag raised in city %d\n",pos);
}
void blue_flag(pair<int,int>tme,int pos){
city[pos].flag=2;
printf("%03d:%02d ",tme.first,tme.second);
printf("blue flag raised in city %d\n",pos);
}
void war(pair<int,int>tme){
get_lazy();war_clr();
// printf("For test,now red have "<<hqrd.ele<<",blue have "<<hqbl.ele<<endl);
for(int i=1;i<=n;i++){
if(city[i].rdid&&city[i].blid){
if(city[i].flag==1||(i%2==1&&city[i].flag!=2)){
int idrd=city[i].rdid,idbl=city[i].blid;
red_active_kill(tme,idrd,idbl,i);
if(city[i].blid&&blsol[city[i].blid].opt!=2) blue_passive_kill(tme,idrd,idbl,i);
if(rdsol[city[i].rdid].opt==1) red_dragon(tme,idrd,i);
if(!city[i].blid) red_get_element(tme,idrd,i);
if(!city[i].rdid) blue_get_element(tme,idbl,i);
}
if(city[i].flag==2||(i%2==0&&city[i].flag!=1)){
int idrd=city[i].rdid,idbl=city[i].blid;
blue_active_kill(tme,idrd,idbl,i);
if(city[i].rdid&&rdsol[city[i].rdid].opt!=2) red_passive_kill(tme,idrd,idbl,i);
if(blsol[city[i].blid].opt==1) blue_dragon(tme,idbl,i);
if(!city[i].rdid) blue_get_element(tme,idbl,i);
if(!city[i].blid) red_get_element(tme,idrd,i);
}
}
if(city[i].rdcnt>=2&&city[i].flag!=1) red_flag(tme,i);
if(city[i].blcnt>=2&&city[i].flag!=2) blue_flag(tme,i);
}
sort(hqrd.vic.begin(),hqrd.vic.end(),red_cmp);
sort(hqbl.vic.begin(),hqbl.vic.end(),blue_cmp);
for(int i=0;i<(int)hqrd.vic.size();i++){
if(hqrd.ele>=8){
hqrd.ele-=8;
rdsol[hqrd.vic[i].second].HP+=8;
}else break;
}
for(int i=0;i<(int)hqbl.vic.size();i++){
if(hqbl.ele>=8){
hqbl.ele-=8;
blsol[hqbl.vic[i].second].HP+=8;
}else break;
}
}
void print_element(pair<int,int>tme){
get_lazy();
printf("%03d:%02d %d elements in red headquarter\n",tme.first,tme.second,hqrd.ele);
printf("%03d:%02d %d elements in blue headquarter\n",tme.first,tme.second,hqbl.ele);
}
signed main(){
// ios::sync_with_stdio(false);
int T=read();
get_charactor();
for(int o=1;o<=T;o++){
printf("Case:%d\n",o);
prework();
for(int i=0;i<=t;i+=10){
pair<int,int>tme=make_pair(i/60,i%60);
// printf("%d %d\n",tme.first,tme.second);
if(tme.second==0) get_birth(tme);
if(tme.second==10) step(tme);
if(judge_win(tme)) break;
if(tme.second==20) spawn();
if(tme.second==30) get_elements(tme);
if(tme.second==40) war(tme);
if(tme.second==50) print_element(tme);
}
}
return 0;
}
本文来自博客园,作者:冬天丶的雨,转载请注明原文链接:https://www.cnblogs.com/WintersRain/p/16755001.html
为了一切不改变的理想,为了改变不理想的一切