【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系列故事——为什么时光不能倒流 ---好水!!
我以为我会是最坚强的那一个 我还是高估了自己 我以为你会是最无情的那一个 还是我贬低了自己 就算不能够在一起 我还是为你担心 就算你可能听不清 也代表我的心意 那北极星的眼泪 闪过你曾经的眼角迷离 那 ...
随机推荐
- c#图像灰度化、灰度反转、二值化
图像灰度化:将彩色图像转化成为灰度图像的过程成为图像的灰度化处理.彩色图像中的每个像素的颜色有R.G.B三个分量决定,而每个分量有255中值可取,这样一个像素点可以有1600多万(255*255*25 ...
- MVC 页面传参到另一个页面
写法一: @{ViewData["partData"]="哇哈哈哈哈";} @{Html.RenderPartial("~/Views/Home ...
- 深入理解php内核——读书笔记1
第一章 基础准备 宏定义 #字符串化 ##连接符 do{}while(0) 多行 全局宏: EG.PG 第二章 用户代码的执行 php请求的生命周期 SAPI接口 php脚本执行 第三章 变量及数据类 ...
- yii2常用的migrate命令
开发中经常会用到的方法小结: 1../yii migrate xxx_xx 在表中插入某字段 : public function up() {$this->addColumn('{{applic ...
- Python: 列表,元组,字典的区别
Python中有3种内建的数据结构:列表,元组和字典 1.列表 list是处理一组有序项目的数据结构,即可以在一个列表中存储一个序列的项目.列表中项目应该包括在方括号中,这样python就知道是在指明 ...
- python六剑客:map()、lambda()、filter()、reduce()、推导类表、切片
一:map():映射 map()有两个参数,一个函数,一个序列,序列中每一个元素都会做为参数传给前边的函数,然后生成新的列表, 第二个参数必须用一个序列:元祖,列表,字符串 >>> ...
- 2016NOI冬令营day4
上午:随机算法/近似算法与随机算法的分析方法与应用实例 不懂,完全滑水QAQ :( 下午:计算理论与NP问题 只有讲2-sat和3-sat的时候能听懂,其他的基本都在滑水:( 晚上说是什么中学生学术训 ...
- P4052 [JSOI2007]文本生成器
P4052 [JSOI2007]文本生成器 AC自动机+dp 优秀题解传送门 设f[ i ][ j ]表示串的长度为 i ,当前在 j 点时不可识别的串的方案数 最后用总方案数减去不可识别方案数就是答 ...
- expect交互式创建账号密码
这个脚本是我在建立samba用户的时候用到的,一开始我是一步一步的操作,后来嫌麻烦了,就写了这个脚本,也学习了一下expect. #!/usr/bin/expectset user [lindex $ ...
- CF#338D. GCD Table
传送门 简单的中国剩余定理练习. 首先行数一定是$lcm$,然后只要确定最小的列数就能判定解合不合法了. 我们可以得到线性模方程组: $y \equiv 0 \pmod{a_1}$ $y+1 \equ ...