2014 ACM/ICPC Asia Regional Guangzhou Online
Wang Xifeng's Little Plot http://acm.hdu.edu.cn/showproblem.php?pid=5024
预处理出每个点八个方向能走的最远距离,然后枚举起点,枚举方向,每走一步都要枚举左转和右转的情况,因为预处理好了,所以可以直接算出来。
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- const int M=;
- char a[M][M];
- int n,dp[M][M][];
- int dx[]={-,-,,,,,,-};
- int dy[]={,,,,,-,-,-};
- bool inside(const int &x,const int &y){
- if(x>=&&x<n&&y>=&&y<n) return true;return false;
- }
- int getfar(int x,int y,int dir){
- int res=;
- while(true){
- x+=dx[dir];
- y+=dy[dir];
- if(!inside(x,y)||a[x][y]=='#') break;
- res++;
- }
- return res;
- }
- int turnleft(int dir){
- return (dir+)%;
- }
- int turnright(int dir){
- return (dir+)%;
- }
- int solve(int x,int y,int dir){
- int res=,step=,left=turnleft(dir),right=turnright(dir);
- while(true){
- x+=dx[dir];
- y+=dy[dir];
- if(!inside(x,y)||a[x][y]=='#') break;
- step++;
- res=max(res,step+dp[x][y][left]);
- res=max(res,step+dp[x][y][right]);
- }
- return res;
- }
- int main(){
- while(~scanf("%d",&n),n){
- for(int i=;i<n;i++){
- scanf("%s",a[i]);
- }
- for(int i=;i<n;i++){
- for(int j=;j<n;j++){
- for(int k=;k<;k++){
- if(a[i][j]=='#'){
- dp[i][j][k]=-;
- }
- else{
- dp[i][j][k]=getfar(i,j,k);
- }
- }
- }
- }
- int ans=;
- for(int i=;i<n;i++){
- for(int j=;j<n;j++){
- if(a[i][j]=='.'){
- for(int k=;k<;k++){
- int now=solve(i,j,k);
- ans=max(ans,now);
- }
- }
- }
- }
- printf("%d\n",ans);
- }
- return ;
- }
A Corrupt Mayor's Performance Art http://acm.hdu.edu.cn/showproblem.php?pid=5023
成段更新。
- #include<cstdio>
- #include<cstring>
- #define mt(a,b) memset(a,b,sizeof(a))
- #define lrrt int L,int R,int rt
- #define iall 1,n,1
- #define imid int mid=(L+R)>>1
- #define lson L,mid,rt<<1
- #define rson mid+1,R,rt<<1|1
- const int M=;
- struct T{
- int cover,lazy;
- }tree[M<<];
- void build(lrrt){
- tree[rt].cover=;
- tree[rt].lazy=;
- if(L==R) return ;
- imid;
- build(lson);
- build(rson);
- }
- void pushdown(int rt){
- if(tree[rt].lazy){
- tree[rt<<].lazy=tree[rt<<|].lazy=tree[rt<<].cover=tree[rt<<|].cover=tree[rt].lazy;
- tree[rt].lazy=;
- }
- }
- void pushup(int rt){
- tree[rt].cover=tree[rt<<].cover==tree[rt<<|].cover?tree[rt<<].cover:;
- }
- void update(int x,int y,int z,lrrt){
- if(x<=L&&R<=y){
- tree[rt].cover=tree[rt].lazy=z;
- return;
- }
- imid;
- pushdown(rt);
- if(mid>=x) update(x,y,z,lson);
- if(mid<y) update(x,y,z,rson);
- pushup(rt);
- }
- bool vis[];
- void query(int x,int y,lrrt){
- if(L==R){
- vis[tree[rt].cover]=true;
- return ;
- }
- imid;
- if(x<=L&&R<=y){
- if(tree[rt].cover){
- vis[tree[rt].cover]=true;
- return ;
- }
- pushdown(rt);
- query(x,y,lson);
- query(x,y,rson);
- return ;
- }
- pushdown(rt);
- if(mid>=x) query(x,y,lson);
- if(mid<y) query(x,y,rson);
- }
- int main(){
- int n,m,x,y,z;
- char op[];
- while(~scanf("%d%d",&n,&m),n|m){
- build(iall);
- while(m--){
- scanf("%s%d%d",op,&x,&y);
- if(op[]=='P'){
- scanf("%d",&z);
- update(x,y,z,iall);
- }
- else{
- mt(vis,);
- query(x,y,iall);
- bool flag=false;
- for(int i=;i<=;i++){
- if(vis[i]){
- if(flag) printf(" ");
- printf("%d",i);
- flag=true;
- }
- }
- puts("");
- }
- }
- }
- return ;
- }
Saving Tang Monk http://acm.hdu.edu.cn/showproblem.php?pid=5025
集齐m把钥匙,就可以拯救唐僧,没集齐也可以从他身上踩过去,拿钥匙必须从小到大拿,蛇只要杀一次,所以要记录钥匙的状态和蛇是否被杀的状态。bfs。
- #include<cstdio>
- #include<cstring>
- #include<cctype>
- #include<queue>
- #define mt(a,b) memset(a,b,sizeof(a))
- using namespace std;
- const int M=;
- char a[M][M];
- int n,m;
- struct Snake{
- int x,y;
- }ts[];
- struct Q{
- int step,sta,x,y,snake;
- friend bool operator <(const Q &a,const Q &b){
- return a.step>b.step;
- }
- }now,pre;
- priority_queue<Q> q;
- bool vis[M][M][<<];
- int dx[]={,,,-};
- int dy[]={,-,,};
- int getkey(const int &psta,const int &x,const int &y){
- int ressta=psta;
- if(isdigit(a[x][y])){
- int his=a[x][y]-'';
- his=<<(his-);
- if(his-==psta){
- ressta|=his;
- }
- }
- return ressta;
- }
- int bfs(){
- int ls=;
- for(int i=;i<n;i++){
- for(int j=;j<n;j++){
- if(a[i][j]=='K'){
- now.x=i;
- now.y=j;
- }
- if(a[i][j]=='S'){
- ts[ls].x=i;
- ts[ls].y=j;
- ls++;
- }
- }
- }
- now.snake=;
- now.sta=;
- now.step=;
- mt(vis,);
- vis[now.x][now.y][now.sta]=true;
- int End=(<<m)-;
- while(!q.empty()) q.pop();
- q.push(now);
- while(!q.empty()){
- pre=q.top();
- q.pop();
- if(a[pre.x][pre.y]=='T'&&pre.sta==End) return pre.step;
- for(int i=;i<;i++){
- int tx=pre.x+dx[i];
- int ty=pre.y+dy[i];
- if(tx>=&&tx<n&&ty>=&&ty<n&&a[tx][ty]!='#'){
- now.sta=getkey(pre.sta,tx,ty);
- if(!vis[tx][ty][now.sta]){
- vis[tx][ty][now.sta]=true;
- now.x=tx;
- now.y=ty;
- now.snake=pre.snake;
- if(a[tx][ty]=='S'){
- int id=;
- for(int j=;j<ls;j++){
- if(ts[j].x==tx&&ts[j].y==ty){
- id=j;
- break;
- }
- }
- if((now.snake>>id)&){
- now.step=pre.step+;
- }
- else{
- now.snake|=(<<id);
- now.step=pre.step+;
- }
- }
- else{
- now.step=pre.step+;
- }
- q.push(now);
- }
- }
- }
- }
- return -;
- }
- int main(){
- while(~scanf("%d%d",&n,&m),n|m){
- for(int i=;i<n;i++){
- scanf("%s",a[i]);
- }
- int ans=bfs();
- if(ans==-) puts("impossible");
- else printf("%d\n",ans);
- }
- return ;
- }
end
2014 ACM/ICPC Asia Regional Guangzhou Online的更多相关文章
- HDU 5029 Relief grain(离线+线段树+启发式合并)(2014 ACM/ICPC Asia Regional Guangzhou Online)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5029 Problem Description The soil is cracking up beca ...
- hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi'an Online)
Mart Master II Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5000 2014 ACM/ICPC Asia Regional Anshan Online DP
Clone Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other) Total Submiss ...
- 2014 ACM/ICPC Asia Regional Shanghai Online
Tree http://acm.hdu.edu.cn/showproblem.php?pid=5044 树链剖分,区间更新的时候要用on的左++右--的标记方法,要手动扩栈,用c++交,综合以上的条件 ...
- 2014 ACM/ICPC Asia Regional Anshan Online
默默的签到 Osu! http://acm.hdu.edu.cn/showproblem.php?pid=5003 #include<cstdio> #include<algorit ...
- 2014 ACM/ICPC Asia Regional 北京 Online
G - Grade Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of mushroo ...
- 2014 ACM/ICPC Asia Regional Xi'an Online
03 hdu5009 状态转移方程很好想,dp[i] = min(dp[j]+o[j~i]^2,dp[i]) ,o[j~i]表示从j到i颜色的种数. 普通的O(n*n)是会超时的,可以想到o[]最大为 ...
- HDU 5010 Get the Nut(2014 ACM/ICPC Asia Regional Xi'an Online)
思路:广搜, 因为空格加上动物最多只有32个那么对这32个进行编号,就能可以用一个数字来表示状态了,因为只有 ‘P’ 'S' 'M' '.' 那么就可以用4进制刚好可以用64位表示. 接下去每次就 ...
- HDU 5002 Tree(动态树LCT)(2014 ACM/ICPC Asia Regional Anshan Online)
Problem Description You are given a tree with N nodes which are numbered by integers 1..N. Each node ...
随机推荐
- Spark基础排序+二次排序(java+scala)
1.基础排序算法 sc.textFile()).reduceByKey(_+_,).map(pair=>(pair._2,pair._1)).sortByKey(false).map(pair= ...
- 会写网页 就会写手机APP -- Hybrid Mobile Apps for ASP.NET Developers
您好,这篇文章是我的BLOG发出,原始出处在此: 会写网页 就会写手机APP -- Hybrid Mobile Apps for ASP.NET Developers http://www.dotbl ...
- jquery mobile最棘手的一个问题
大多数jquery mobile开发的妹子们都碰到过这个问题: 如何调用loading效果 这里给出一段代码,赶紧练手吧. //显示loading function showLoading(){ ...
- python ssh
使用python包paramiko实现通过ssh的安全远程访问 使用pip下载安装paramiko,提示会缺一个crypto包,用pip将这个包也安好,python就可以正常引用paramiko了 一 ...
- [div+css布局]命名规则
//首页可能碰到的 页头:header登录条:loginBar标志:logo侧栏:sideBar广告:banner导航:nav子导航:subNav菜单:menu子菜单:subMenu搜索:search ...
- sublimeLinter-jshint 配置
这几天知道sublime3有可以对javascript进行语法检查的文件,折腾了一上午,搞定了. 记录一下步骤: 1.先安装nodejs. 2.npm install jshint -g 3.通过su ...
- Oracle Database Concepts:介绍模式对象(Introduction to Schema Objects)
数据库模式(schema)是数据结构的逻辑容器,被称作模式对象(schema objects) 每一个数据库用户拥有一个和用户名相同的模式,例如hr用户拥有hr模式. 在一个产品数据库中,模式的拥有者 ...
- JQuery ----文档处理
1.append(content|fn) 概述 向每个匹配的元素内部追加内容. 这个操作与对指定的元素执行appendChild方法,将它们添加到文档中的情况类似. 2.appendTo(conten ...
- 社保系列11《ATR》
1) 冷复位(Cold Reset) 当IC卡的电源电压和其他信号从静止状态中复苏且申请复位信号时,IC卡产生的复位. 2) 热复位(Warm Reset) 在时钟(CLK)和电源电压(VCC)处 ...
- MIFARE系列8《D8M1.exe》
软件名:D8M1.exe 更新时间:2014.06.28 操作系统:windowAll 外部设备:D8读卡器 D8M1可以对MIFARE块读写操作,支持1K,4K.检验KEY后返回SAK,QTAQ,U ...