【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系列故事——为什么时光不能倒流 ---好水!!
我以为我会是最坚强的那一个 我还是高估了自己 我以为你会是最无情的那一个 还是我贬低了自己 就算不能够在一起 我还是为你担心 就算你可能听不清 也代表我的心意 那北极星的眼泪 闪过你曾经的眼角迷离 那 ...
随机推荐
- ubuntu 安装ftp nginx tomcat,mysql
tomcat sudo apt-get install tomcat 访问方式,http://loclahost:8080 进入sbin目录下 sudo ./startup.sh开启 sudo ./s ...
- 从jvm来看,scala中的@究竟是个什么鬼?@模式匹配符号(scala 词法分析 语法分析常用)
从jvm来看,scala中的@究竟是个什么鬼? 我也是初步尝试来看jvm的类文件,又是初次来分析@,如不对的地方,请各位指正! 先看一下@ 是个什么? object TestScala { def m ...
- [py]django前台处理后端返回的各类数据
参考 要完成的任务 返回str 返回list 返回arr 前端遍历 关键字 if for语句处理str list dict - 遍历字典 for语句 {% for key, value in info ...
- Py-lamda表达式学习【转载】
转自:https://blog.csdn.net/zjuxsl/article/details/79437563 1.语法定义 在Python中,lambda的语法是唯一的.其形式如下: lambda ...
- Look for the Air Jordan 32 in full family sizing
Following the release of the 'Rosso Corsa' colorway, Jordan Brand is now set to officially launch th ...
- 借root之名,行流氓之实,劝告,root需谨慎
20160425++++++ 今日再回头看这篇文章,貌似有点偏激了一点,不过xda论坛上有个疑似kingroot开发团队的用户说明了kingroot确实对supersu做了限制,说是supersu在替 ...
- linux基础命令---umask
umask 指定创建文件时所需要的权限掩码,掩码的执行权限对于文件没有效果.如果模式以数字开头,则解释为八进制数字:否则解释为符号模式掩码,类似于chmod(1)所接受的模式掩码.如果省略模式,则打印 ...
- 使用 jQuery 进行前端验证
前段验证脚本的教程,其基础为jQuery的插件validate. 一.可以验证哪些信息 要求输入不能为空 要求输入格式必须为电子邮箱 要求输入格式必须为URL 要求输入格式必须为日期 要求输入格 ...
- ThinkPHP5跨控制器调用
1.在application\index\controller\文件夹里新建User.php <?php namespace app\index\controller; class User{ ...
- 20145122《敏捷开发与XP实践 》实验三实验报告
实验名称 敏捷开发与XP实践 实验内容 1.团队代码要使用git在实验楼中托管,要使用结对同学中的一个同学的账号托管. 2.使用git推送代码并对结对同学的代码修改完成后再git推送. 3.掌握重构流 ...