【NOI2013】小Q的修炼
题目链接:http://uoj.ac/problem/123
又开提答坑啦,要不是一定要讲题谁他妈要这样伤害自己
CASE 1,2
首先可以打一个通用暴力,用于模拟操作过程,对于每一个操作随机一个选择,然后跑多次记录答案。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<ctime>
using namespace std;
#define maxn 1000010
#define llg long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,dl[maxn],tail,anst,ans[maxn],val[maxn],maxl,cs;
llg T=;
char ch,s[maxn]; llg next_x(llg x){x++; while (s[x]==' ') x++; return x;} struct node
{
llg type;
llg t1,v1,t2,v2,fu,to1,to2;
}a[maxn]; llg make_number(llg &x)
{
llg val=,p=;
if (s[x]=='-') x++,p=-;
while (s[x]>='' && s[x]<='')
{
val*=;
val+=s[x]-'';
x++;
}
return val*p;
} void Decompression_(llg i)
{ llg x=;
if (s[x]=='v')
{
a[i].type=;
x=next_x(x);
a[i].v1=make_number(x);
x=next_x(x);
if (s[x]=='+') a[i].fu=;else a[i].fu=-;
x=next_x(x);
if (s[x]=='c') a[i].t2=; else a[i].t2=;
x=next_x(x);
a[i].v2=make_number(x);
}
if (s[x]=='s')
{
a[i].type=;
x=next_x(x);
a[i].to1=make_number(x);
x=next_x(x);
a[i].to2=make_number(x);
}
if (s[x]=='i')
{
a[i].type=;
x=next_x(x);
if (s[x]=='c') a[i].t1=; else a[i].t1=;
x=next_x(x);
a[i].v1=make_number(x);
x=next_x(x);
if (s[x]=='c') a[i].t2=; else a[i].t2=;
x=next_x(x);
a[i].v2=make_number(x);
x=next_x(x);
a[i].to1=make_number(x);
x=next_x(x);
a[i].to2=make_number(x);
}
} bool pd(char ch)
{
if (ch>='' && ch<='') return ;
if (ch=='v' || ch=='i' || ch=='+' || ch=='-' || ch=='s' || ch=='c' || ch==' ') return ;
return ;
} void init()
{
cin>>n>>m;
ch=getchar();
for (llg i=;i<=n;i++)
{
llg len=;
ch=getchar();
while (pd(ch)) {s[++len]=ch; ch=getchar();}
Decompression_(i);
for (llg i=;i<=len+;i++) s[i]='\0';
}
} void work()
{
cs=;
llg x=,cho;
tail=;
for (llg i=;i<=m;i++) val[i]=;
while (x>= && x<=n)
{
if (a[x].type==)
{
if (a[x].t2) val[a[x].v1]+=val[a[x].v2]*a[x].fu;
else val[a[x].v1]+=a[x].v2*a[x].fu;
x++;
}
if (a[x].type==)
{
cs++;
if (cs>) {return ;}
cho=rand()%+;
if (cho==) x=a[x].to1; else x=a[x].to2;
dl[++tail]=cho;
}
if (a[x].type==)
{
llg val1,val2;
if (a[x].t1) val1=val[a[x].v1];else val1=a[x].v1;
if (a[x].t2) val2=val[a[x].v2];else val2=a[x].v2;
if (val1<val2) x=a[x].to1; else x=a[x].to2;
}
}
} int main()
{
yyj("train7");
init();
srand(time(NULL));
fclose(stdin);
// freopen("make.in","r",stdin);
maxl=(llg)1e16*-;
T=;
while (T--)
{
// system("make.exe");
work();
if (val[]>maxl && cs<=)
{
maxl=val[];
anst=tail;
for (llg i=;i<=anst;i++) ans[i]=dl[i];
}
}
// cout<<maxl<<endl;
for (llg i=;i<=anst;i++) cout<<ans[i]<<endl;
return ;
}
这样可以过第一,二个点,然后一共有31分。。。。
Ans1:
Ans2:
CASE 3
可以发现有很多块,但是每一个块会根据在这个块中的所有变量的变化来修改变量1的值,每一个块中又分为10+个小块,小块中是对于变量2-m的修改,小块首有选择语句,可以选择是否跳过这个小块。
块与块之间又互不影响,因为块尾会把除了变量1的所有变量全部清空。
所以说,我们可以爆搜每一个块中的小块的决策,然后统计答案即可。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<ctime>
using namespace std;
#define maxn 1000010
#define llg long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,dl[maxn],tail,anst,ans[maxn],val[maxn],maxl,cs;
llg T=;
char ch,s[maxn]; llg next_x(llg x){x++; while (s[x]==' ') x++; return x;} struct node
{
llg type;
llg t1,v1,t2,v2,fu,to1,to2;
}a[maxn]; llg make_number(llg &x)
{
llg val=,p=;
if (s[x]=='-') x++,p=-;
while (s[x]>='' && s[x]<='')
{
val*=;
val+=s[x]-'';
x++;
}
return val*p;
} void Decompression_(llg i)
{ llg x=;
if (s[x]=='v')
{
a[i].type=;
x=next_x(x);
a[i].v1=make_number(x);
x=next_x(x);
if (s[x]=='+') a[i].fu=;else a[i].fu=-;
x=next_x(x);
if (s[x]=='c') a[i].t2=; else a[i].t2=;
x=next_x(x);
a[i].v2=make_number(x);
}
if (s[x]=='s')
{
a[i].type=;
x=next_x(x);
a[i].to1=make_number(x);
x=next_x(x);
a[i].to2=make_number(x);
}
if (s[x]=='i')
{
a[i].type=;
x=next_x(x);
if (s[x]=='c') a[i].t1=; else a[i].t1=;
x=next_x(x);
a[i].v1=make_number(x);
x=next_x(x);
if (s[x]=='c') a[i].t2=; else a[i].t2=;
x=next_x(x);
a[i].v2=make_number(x);
x=next_x(x);
a[i].to1=make_number(x);
x=next_x(x);
a[i].to2=make_number(x);
}
} bool pd(char ch)
{
if (ch>='' && ch<='') return ;
if (ch=='v' || ch=='i' || ch=='+' || ch=='-' || ch=='s' || ch=='c' || ch==' ') return ;
return ;
} void init()
{
cin>>n>>m;
ch=getchar();
for (llg i=;i<=n;i++)
{
llg len=;
ch=getchar();
while (pd(ch)) {s[++len]=ch; ch=getchar();}
Decompression_(i);
for (llg i=;i<=len+;i++) s[i]='\0';
}
} void work(llg x,llg up)
{
cs=;
llg cho;
tail=;
for (llg i=;i<=m;i++) val[i]=;
while (x>= && x<=up)
{
if (a[x].type==)
{
if (a[x].t2) val[a[x].v1]+=val[a[x].v2]*a[x].fu;
else val[a[x].v1]+=a[x].v2*a[x].fu;
x++;
continue;
}
if (a[x].type==)
{
cs++;
if (cs>) {return ;}
cho=rand()%+;
if (cho==) x=a[x].to1; else x=a[x].to2;
dl[++tail]=cho;
continue;
}
if (a[x].type==)
{
llg val1,val2;
if (a[x].t1) val1=val[a[x].v1];else val1=a[x].v1;
if (a[x].t2) val2=val[a[x].v2];else val2=a[x].v2;
if (val1<val2) x=a[x].to1; else x=a[x].to2;
continue;
}
}
} int main()
{
yyj("train3");
init();
srand(time(NULL));
fclose(stdin);
for (llg i=;i<=n;i+=)
{
maxl=(llg)1e16*-;
T=;
anst=;
while (T--)
{
work(i,i+);
if (val[]>maxl && cs<=)
{
maxl=val[];
anst=tail;
for (llg i=;i<=anst;i++) ans[i]=dl[i];
}
}
for (llg i=;i<=anst;i++) cout<<ans[i]<<endl;
}
return ;
}
Ans3:
CASE 4,5,6
这些点的特点是只有两个变量,每一次跳转都和变量2有关,而且变量二的变化量并不大,每一个跳转操作并不会往回跳(没有后效性),考虑做一次dp即可。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<ctime>
#include<queue>
using namespace std;
#define maxn 1000010
#define llg long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,tail,anst,ans[maxn],val[maxn],maxl,cs;
llg T=;
char ch,s[maxn]; llg next_x(llg x){x++; while (s[x]==' ') x++; return x;} struct node
{
llg type;
llg t1,v1,t2,v2,fu,to1,to2;
}a[maxn]; llg make_number(llg &x)
{
llg val=,p=;
if (s[x]=='-') x++,p=-;
while (s[x]>='' && s[x]<='')
{
val*=;
val+=s[x]-'';
x++;
}
return val*p;
} void Decompression_(llg i)
{ llg x=;
if (s[x]=='v')
{
a[i].type=;
x=next_x(x);
a[i].v1=make_number(x);
x=next_x(x);
if (s[x]=='+') a[i].fu=;else a[i].fu=-;
x=next_x(x);
if (s[x]=='c') a[i].t2=; else a[i].t2=;
x=next_x(x);
a[i].v2=make_number(x);
}
if (s[x]=='s')
{
a[i].type=;
x=next_x(x);
a[i].to1=make_number(x);
x=next_x(x);
a[i].to2=make_number(x);
}
if (s[x]=='i')
{
a[i].type=;
x=next_x(x);
if (s[x]=='c') a[i].t1=; else a[i].t1=;
x=next_x(x);
a[i].v1=make_number(x);
x=next_x(x);
if (s[x]=='c') a[i].t2=; else a[i].t2=;
x=next_x(x);
a[i].v2=make_number(x);
x=next_x(x);
a[i].to1=make_number(x);
x=next_x(x);
a[i].to2=make_number(x);
}
} bool pd(char ch)
{
if (ch>='' && ch<='') return ;
if (ch=='v' || ch=='i' || ch=='+' || ch=='-' || ch=='s' || ch=='c' || ch==' ') return ;
return ;
} void init()
{
cin>>n>>m;
ch=getchar();
for (llg i=;i<=n;i++)
{
llg len=;
ch=getchar();
while (pd(ch)) {s[++len]=ch; ch=getchar();}
Decompression_(i);
for (llg i=;i<=len+;i++) s[i]='\0';
}
} struct data
{
llg val,k,from;
}dl[maxn]; vector<data>f[maxn]; void in(llg x,data w)
{
llg E=f[x].size();
for (llg i=;i<E;i++)
{
if (f[x][i].k==w.k)
{
if (w.val>f[x][i].val) f[x][i]=w;
return ;
}
}
f[x].push_back(w);
} void work(data w,llg x)
{
llg nx; data nw=w;
nw.from=x;
if (a[x].type==)
{
nx=x+;
if (a[x].v1==)
{
if (a[x].t2)
{
if (a[x].v2==) nw.val+=nw.val;else nw.val+=nw.k;
}
else nw.val+=a[x].v2;
}
else
{
if (a[x].t2)
{
if(a[x].v2==) nw.k+=nw.val; else nw.k+=nw.k;
}
else nw.k+=a[x].v2;
}
in(nx,nw);
return ;
}
if (a[x].type==)
{
nx=a[x].to1;
if (nx>n || n<) nx=;
in(nx,nw);
nx=a[x].to2;
if (nx>n || n<) nx=;
in(nx,nw);
return ;
}
if (a[x].type==)
{
llg v1,v2;
if (a[x].t1) {if (a[x].v1==) v1=nw.val;else v1=nw.k;}else v1=a[x].v1;
if (a[x].t2) {if (a[x].v2==) v2=nw.val;else v2=nw.k;}else v2=a[x].v2;
if (v1<v2) nx=a[x].to1;else nx=a[x].to2;
if (nx>n || n<) nx=;
in(nx,nw);
return ;
} } void dg(data x)
{
} int main()
{
yyj("train4");
init();
srand(time(NULL));
fclose(stdin);
data S; S.val=,S.k=,S.from=-;
f[].push_back(S);
for (llg i=;i<=n;i++)
{
data w;
llg W=f[i].size();
// printf("%lld--->%lld\n",i,W);
for (llg k=;k<W;k++)
{
w=f[i][k];
work(w,i);
}
}
llg W=f[].size();
for (llg i=;i<W;i++)
{
if (f[][i].val>maxl)
{
maxl=f[][i].val;
S=f[][i];
}
}
dg(f[][i]);
return ;
}
Ans4:
Ans5:
Ans6:
【NOI2013】小Q的修炼的更多相关文章
- 「NOI2013」小 Q 的修炼 解题报告
「NOI2013」小 Q 的修炼 第一次完整的做出一个提答,花了半个晚上+一个上午+半个下午 总体来说太慢了 对于此题,我认为的难点是观察数据并猜测性质和读入操作 我隔一会就思考这个sb字符串读起来怎 ...
- uoj123 【NOI2013】小Q的修炼
搞了一下午+半晚上.其实不是很难. 提答题重要的是要发现数据的特殊性质,然后根据不同数据写出不同的算法获得其对应的分数. 首先前两个测试点我们发现可以直接暴搜通过,事实上对于每个数据都暴搜加上一定的次 ...
- HD4505小Q系列故事——电梯里的爱情
Problem Description 细心的同事发现,小Q最近喜欢乘电梯上上下下,究其原因,也许只有小Q自己知道:在电梯里经常可以遇到他心中的女神HR. 电梯其实是个很暧昧的地方,只有在电梯里,小Q ...
- hdu4505小Q系列故事——电梯里的爱情
小Q系列故事——电梯里的爱情 Time Limit: 300/100 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tota ...
- 小Q系列故事——电梯里的爱情
小Q系列故事——电梯里的爱情 Time Limit : 300/100ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total ...
- 平面直接坐标系线段相交问题(小Q(钟神)的问题)
[问题描述] 小 Q 对计算几何有着浓厚的兴趣.他经常对着平面直角坐标系发呆,思考一些有趣的问题.今天,他想到了一个十分有意思的题目:首先,小 Q 会在?轴正半轴和?轴正半轴分别挑选?个点.随后,他将 ...
- hdu---(4515)小Q系列故事——世界上最遥远的距离(模拟题)
小Q系列故事——世界上最遥远的距离 Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)T ...
- HDU-4515 小Q系列故事——世界上最遥远的距离
小Q系列故事——世界上最遥远的距离 Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) ...
- 2013腾讯编程马拉松初赛第二场(3月22日) 小Q系列故事——为什么时光不能倒流 ---好水!!
我以为我会是最坚强的那一个 我还是高估了自己 我以为你会是最无情的那一个 还是我贬低了自己 就算不能够在一起 我还是为你担心 就算你可能听不清 也代表我的心意 那北极星的眼泪 闪过你曾经的眼角迷离 那 ...
随机推荐
- windows使用方法
1:截图搜索英文单词:snipping tool 2: 修改语言,搜索language 3:关闭fn键,按键 fn+esc(fnlock). 就可以将fn关闭和开启.
- Git warning:LF will be replaced by CRLF in readme.txt的原因与解决方案
今天用Git bash遇到的问题,看了几个回答之后发现一个比较有价值的,给大家分享一下,其他很多的回答都有很或多或少存在一些弊端. 原回答地址在stackoverflow上,附上链接--http:// ...
- postman返回参数的截取
同事在使用postman接口测试的时候,遇到这么一个问题,在一个参数里面,返回了一个类似数组的参数,如下: 然后现在需要把数组里面的两个参数分别保存到环境变量里面: 个人的想法是通过截取的方式进行数组 ...
- 使用Fiddler远程抓包
Fiddler简介以及web抓包 一.Fiddler简介 简单来说,Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯.网上简介很多,我们不多说. 二 ...
- jQ live用法
我们给元素绑定单击事件.用得最多的都是$("#id").click(function(){}); 但我们动态添加的元素.这样绑定是不行的.必须借助live $("#id ...
- mysql数据库环境配置中部分问题解决办法
注:原文地址:https://www.cnblogs.com/hezhuoheng/p/9366630.html 其中最重要的,是三个原则:命令按顺序输入.删除了ini(这个不是原则,是我解决问题的一 ...
- Webform和MVC,为什么MVC更好一些?(转)
转自http://www.admin10000.com/document/5277.html 前言 如果你看了最近微软的议程,你会发现他们现在的焦点除了MVC,还是MVC.问题在于为什么微软如此热衷于 ...
- Python:键盘输入input
从键盘读入数据 >>> num=input('利润是:') 利润是:55 >>>
- linux 判断文件最后更新时间 实现监控日志是否有输出功能
linux 判断文件最后更新时间 实现监控日志是否有输出功能. 需求:监控log.txt日志文件,超过一分钟没输出内容就认为是停了,则自动启动程序. 用stat 可以看文件的更新时间stat -c % ...
- Web API设计方法论--比较完整的web api 开发过程
为Web设计.实现和维护API不仅仅是一项挑战:对很多公司来说,这是一项势在必行的任务.本系列将带领读者走过一段旅程,从为API确定业务用例到设计方法论,解决实现难题,并从长远的角度看待在Web上维护 ...