【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系列故事——为什么时光不能倒流 ---好水!!
我以为我会是最坚强的那一个 我还是高估了自己 我以为你会是最无情的那一个 还是我贬低了自己 就算不能够在一起 我还是为你担心 就算你可能听不清 也代表我的心意 那北极星的眼泪 闪过你曾经的眼角迷离 那 ...
随机推荐
- sdut2193救基友记3(三维)
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2193 救基友记3 Time Limit: 10 ...
- weka数据挖掘拾遗(二)---- 特征选择(IG、chi-square)
一.说明 IG是information gain 的缩写,中文名称是信息增益,是选择特征的一个很有效的方法(特别是在使用svm分类时).这里不做详细介绍,有兴趣的可以googling一下. chi-s ...
- SQL CASE 多条件用法
Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN ...
- centos安装samba
yum -y install samba samba-client samba-swat /etc/init.d/smb start chkconfig --level 35 smb on cp -p ...
- sql 各种锁
SELECT * FROM table WITH (HOLDLOCK) 注意: 锁定数据库的一个表的区别 SELECT * FROM table WITH (HOLDLOCK) 其他事务可以读取表,但 ...
- 174. Dungeon Game(动态规划)
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...
- Python: 合并拼接字符串join()| format() | +
将几个小字符串合并成为一个大的字符串 1如果合并的是一个序列,最快的方式是使用join()方法 >>> parts = ['Is', 'Chicago', 'Not', 'Chica ...
- tomcat性能调优 大赞
从“第三天”的性能测试一节中,我们得知了决定性能测试的几个重要指标,它们是: ü 吞吐量 ü Responsetime ü Cpuload ü MemoryUsage 我 们也在第三天的学习中对Apa ...
- 计算概论(A)/基础编程练习2(8题)/4:骑车与走路
#include<stdio.h> int main() { // 待处理的数据数量n ; scanf("%d", &n); float meters[n]; ...
- 什么是IO多路复用?Nginx的处理机制
先来说一下什么是IO复用? IO复用解决的就是并发行的问题,比如多个用户并发访问一个WEB网站,对于服务端后台而言就会产生多个请求,处理多个请求对于中间件就会产生多个IO流对于系统的读写.那么对于IO ...