点击打开链接

Caocao's Bridges

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 446    Accepted Submission(s): 193

Problem Description
Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. But he wouldn't give up. Caocao's army still was not good at water battles, so he came up with another idea. He built many islands in the Changjiang river, and based on those islands, Caocao's army could easily attack Zhou Yu's troop. Caocao also built bridges connecting islands. If all islands were connected by bridges, Caocao's army could be deployed very conveniently among those islands. Zhou Yu couldn't stand with that, so he wanted to destroy some Caocao's bridges so one or more islands would be seperated from other islands. But Zhou Yu had only one bomb which was left by Zhuge Liang, so he could only destroy one bridge. Zhou Yu must send someone carrying the bomb to destroy the bridge. There might be guards on bridges. The soldier number of the bombing team couldn't be less than the guard number of a bridge, or the mission would fail. Please figure out as least how many soldiers Zhou Yu have to sent to complete the island seperating mission.
Input
There are no more than 12 test cases.

In each test case:

The first line contains two integers, N and M, meaning that there are N islands and M bridges. All the islands are numbered from 1 to N. ( 2 <= N <= 1000, 0 < M <= N2 )

Next M lines describes M bridges. Each line contains three integers U,V and W, meaning that there is a bridge connecting island U and island V, and there are W guards on that bridge. ( U ≠ V and 0 <= W <= 10,000 )

The input ends with N = 0 and M = 0.

Output
For each test case, print the minimum soldier number Zhou Yu had to send to complete the mission. If Zhou Yu couldn't succeed any way, print -1 instead.
Sample Input
3 3 1 2 7 2 3 4 3 1 4 3 2 1 2 7 2 3 4 0 0
Sample Output
-1 4
Source
2013 ACM/ICPC Asia Regional Hangzhou Online
Recommend
liuyiding

题意是说曹操有n个岛,岛与岛之间有桥,桥上有士兵看守。周瑜想要派兵去炸掉桥,但是只能炸一次,而且兵数必须不少于看守桥的士兵。问你周瑜最少派多少兵,就可以将曹操的一个岛或者一些岛跟其它的岛相离。如果周瑜不能成功,则输出-1.

此题是双联通分量求割桥的类型。另外此题有不少坑:

1:可能有重边。

2:如果最小边权为0,则需要一个人。

3:如果原图不连通,则输出0.

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define M 10010
#define inf 0x3f3f3f3f
using namespace std;
int dfn[M],low[M],head[M],pre[M];
int n,m,tot,ind;struct Edg
{int to,next,w;bool cut;
}edg[2000010];void init()
{tot=0;ind=0;memset(dfn,0,sizeof(dfn));memset(low,0,sizeof(low));memset(head,-1,sizeof(head));for(int i=0;i<=n;i++)pre[i]=i;
}void addedge(int u,int v,int w)
{edg[tot].to=v;edg[tot].next=head[u];edg[tot].w=w;edg[tot].cut=false;//初始化head[u]=tot++;
}int find(int x)
{while(x!=pre[x])x=pre[x];return x;
}void unio(int a,int b)
{int x=find(a);int y=find(b);if(x!=y)pre[x]=y;
}int dfs(int u,int pre)
{dfn[u]=low[u]=++ind;int sum=0,v;for(int i=head[u];i!=-1;i=edg[i].next){v=edg[i].to;if(v==pre&&sum==0){sum++;continue;}if(!dfn[v]){dfs(v,u);if(low[u]>low[v])low[u]=low[v];if(low[v]>dfn[u])//一条无向边(u,v)是桥,当且仅当(u,v)为树枝边,且满足DFS(u)<Low(v){edg[i].cut=true;edg[i^1].cut=true;}}else if(low[u]>dfn[v])low[u]=dfn[v];}
}int tarjan(int n)
{for(int i=1;i<=n;i++)if(!dfn[i])dfs(i,i);int answer=inf;for(int u=1;u<=n;u++)for(int i=head[u];i!=-1;i=edg[i].next)if(edg[i].cut)answer=min(answer,edg[i].w);//找最小的桥if(answer==inf)return -1;if(answer==0)answer++;//如果割的桥为0,则要+1return answer;
}int main()
{//freopen("in.txt","r",stdin);while(scanf("%d%d",&n,&m),n|m){init();int a,b,c;while(m--){scanf("%d%d%d",&a,&b,&c);if(a==b)continue;addedge(a,b,c);addedge(b,a,c);unio(a,b);}bool flag=true;for(int i=1;i<=n;i++)//判断是否联通if(find(i)!=find(1))flag=false;if(!flag)printf("0\n");elseprintf("%d\n",tarjan(n));}return 0;
}

点击打开链接

The Donkey of Gui Zhou

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 309    Accepted Submission(s): 119

Problem Description
There was no donkey in the province of Gui Zhou, China. A trouble maker shipped one and put it in the forest which could be considered as an N×N grid. The coordinates of the up-left cell is (0,0) , the down-right cell is (N-1,N-1) and the cell below the up-left cell is (1,0)..... A 4×4 grid is shown below:

The donkey lived happily until it saw a tiger far away. The donkey had never seen a tiger ,and the tiger had never seen a donkey. Both of them were frightened and wanted to escape from each other. So they started running fast. Because they were scared, they were running in a way that didn't make any sense. Each step they moved to the next cell in their running direction, but they couldn't get out of the forest. And because they both wanted to go to new places, the donkey would never stepped into a cell which had already been visited by itself, and the tiger acted the same way. Both the donkey and the tiger ran in a random direction at the beginning and they always had the same speed. They would not change their directions until they couldn't run straight ahead any more. If they couldn't go ahead any more ,they changed their directions immediately. When changing direction, the donkey always turned right and the tiger always turned left. If they made a turn and still couldn't go ahead, they would stop running and stayed where they were, without trying to make another turn. Now given their starting positions and directions, please count whether they would meet in a cell.
Input
There are several test cases.

In each test case:
First line is an integer N, meaning that the forest is a N×N grid.

The second line contains three integers R, C and D, meaning that the donkey is in the cell (R,C) when they started running, and it's original direction is D. D can be 0, 1, 2 or 3. 0 means east, 1 means south , 2 means west, and 3 means north.

The third line has the same format and meaning as the second line, but it is for the tiger.

The input ends with N = 0.  ( 2 <= N <= 1000, 0 <= R, C < N)

Output
For each test case, if the donkey and the tiger would meet in a cell, print the coordinate of the cell where they meet first time.  If they would never meet, print -1 instead.
Sample Input
2 0 0 0 0 1 2 4 0 1 0 3 2 0 0
Sample Output
-1 1 3
Source
2013 ACM/ICPC Asia Regional Hangzhou Online
Recommend
liuyiding

比赛时间花了三个小时硬是没做出来了,明明都想到是搜索和模拟了,哎,比赛完之后又做了两个小时才做出来,害的我都失眠了,网络赛真是伤不起。

题意是说在一个n*n的矩阵里面,有一只驴和一只老虎,给了你它们的起始坐标和方向,当它们无路可走的时候,驴总是向右拐,如果仍然走不动,则停止;而老虎总是向左拐,如果仍然走不动的话,也停止。如果它们在途中相遇,输出相遇时的坐标,如果始终相遇不到,则输出-1.

#include<stdio.h>
#include<string.h>
#define M 1007
using namespace std;
int vis1[M][M],vis2[M][M];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int n,x1,y1,d1,x2,y2,d2;
int main()
{while(scanf("%d",&n),n){scanf("%d%d%d",&x1,&y1,&d1);scanf("%d%d%d",&x2,&y2,&d2);memset(vis1,0,sizeof(vis1));memset(vis2,0,sizeof(vis2));bool flag=false,stop1=false,stop2=false;vis1[x1][y1]=1;vis2[x2][y2]=1;int xx1,yy1,xx2,yy2;while(1){if(x1==x2&&y1==y2){flag=true;break;}if(stop1&&stop2)//如果两个都停下来了,则结束,它们不能相遇break;vis1[x1][y1]=1;vis2[x2][y2]=1;if(!stop1)//如果驴还没有停下来{xx1=x1+dx[d1];yy1=y1+dy[d1];if(xx1>=0&&xx1<n&&yy1>=0&&yy1<n&&!vis1[xx1][yy1])//如果能够继续往前走{x1=xx1;y1=yy1;d1=d1;}else//不能继续走了{xx1=x1+dx[(d1+1)%4];//转了方向之后的坐标yy1=y1+dy[(d1+1)%4];if(xx1>=0&&xx1<n&&yy1>=0&&yy1<n&&!vis1[xx1][yy1])//如果转了方向之后能够继续走{x1=xx1;y1=yy1;d1=(d1+1)%4;}else//如果转了方向之后不能走了{x1=x1;y1=y1;stop1=true;//就停下来}}}if(!stop2)//同驴一样{xx2=x2+dx[d2];yy2=y2+dy[d2];if(xx2>=0&&xx2<n&&yy2>=0&&yy2<n&&!vis2[xx2][yy2]){x2=xx2;y2=yy2;d2=d2;}else{xx2=x2+dx[((d2-1)%4+4)%4];yy2=y2+dy[((d2-1)%4+4)%4];if(xx2>=0&&xx2<n&&yy2>=0&&yy2<n&&!vis2[xx2][yy2]){x2=xx2;y2=yy2;d2=((d2-1)%4+4)%4;}else{x2=x2;y2=y2;stop2=true;}}}}if(flag)printf("%d %d\n",x1,y1);elseprintf("-1\n");}return 0;
}

2013年ACM网络赛杭州赛区相关推荐

  1. ACM网络赛金华赛区的一道关于树的题:Family Name List

    三场网络赛终于告一段落了!唉,实力太弱了!跟北大.清华这些家伙差距太远了,比"我在你身边你却不知道我爱你"的距离还要远! 这道题没有来得及提交,自己下来写完的,把样例过了!留在博客 ...

  2. 2013 年亚洲赛杭州赛区卡题总结

         今天这场比赛,真的打的很痛苦,从头卡到尾,实在是无语,哭死,这是一次严重的战略失误!!! 好吧!就先描述一下所有的比赛过程吧! 赛前安排,中场12:30无论如何必须把所有题看一遍,然后挑几题 ...

  3. 2013年长沙网络赛G题

    题目:http://acm.zju.edu.cn/changsha/showProblem.do?problemId=28 题意:给一个数n,范围是[2,80000],使用加,乘运算和最多3个素数,有 ...

  4. 2012网赛杭州赛区

    1002 arrest 有k个警察在0点按顺序遍历1到n去抓小偷, 这样构图时就要对编号小的连向编号大的, 之前要floyd处理. 我赛后的构图:对每个点的遍历有个限制是必须是1次, 由于是费用流, ...

  5. To Be an Dream Architect(2010年ACM亚洲预选赛杭州赛区第三题))

    ProblemC. To Be an Dream Architect Description The "dreamarchitect" is the key role in a t ...

  6. 2014 ACM/ICPC 北京赛区网络赛解题报告汇总

    首页 算法竞赛» 信息聚合 ONLINE JUDGE 书刊杂志 BLOG» 新闻故事» 招聘信息» 投稿须知 2014 ACM/ICPC 北京赛区网络赛解题报告汇总 九月 21st, 2014 | P ...

  7. 2011 ACM/ICPC 福州赛区网络赛解题报告

    第一次写网络赛的题解,福州赛区网络赛作为我第一年ACM最后一次网络赛酱油,画了一个很像逗号的句号.....好吧,还得为北京现场赛准备啊准备....... 这次酱油打的很犀利,貌似出第一题很快,之后节奏 ...

  8. 2018年 ACM/ICPC亚洲区域赛 青岛赛区现场赛 比赛总结

    首先祝贺自己收获了ACM生涯中的第二枚铜牌. 首先吐槽一下中石油: 周六早上来到中国石油大学,连个志愿者小姐姐都没看到.(但是看到了女装大佬).报完到之后发现教练少了一张午餐券(要不要这么粗心).为了 ...

  9. 2019 ACM - ICPC 上海网络赛 E. Counting Sequences II (指数型生成函数)

    繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...

最新文章

  1. 阿里云首席架构师唐洪:拥抱开源的云端更具生命力
  2. 机器学习数据预处理之缺失值:插值法填充+ lagrange插值+拉格朗日插值
  3. 分布式服务(RPC)+分布式消息队列(MQ)面试题精选
  4. PostgreSQL client's startup packet different between logical and normal stream replication
  5. web模拟telnet
  6. Transform.Rotate 旋转
  7. raspberry pi_我如何使用Raspberry Pi与孙辈联系
  8. 中职计算机应用基础微课获奖视频,浅谈微课在中职计算机应用基础教学中的应用...
  9. 从DB-Engines看传统数据库生存状况
  10. ABAP Util代码
  11. csdn如何修改文字体及颜色
  12. 关于折叠屏手机的适配
  13. fei 正则表达式_正则表达式大爆料
  14. 爱莫完成A+轮融资,打造基于实体零售数据引擎的Metachain Store平台
  15. 大数据是什么,大数据的特点主要有哪些,应该怎么运用?
  16. 【小样本基础】Meta-Learning 元学习流程:图解MAML代码
  17. cartographer源码解析(二)node_main.cc文件详解
  18. Muli3D源码分析(1) - 框架概览
  19. 怎样开始学做自媒体?怎么起步?
  20. 油猴脚本 from greasyfork

热门文章

  1. 计算机上全部是应用程序,电脑桌面的所有应用程序.exe名称后缀都变成.lnk的解决方法...
  2. SAP为何能够屡屡斩获大单?
  3. node.js基于Vue的英语在线学习网站 vscode+mysql
  4. 什么是JavaScript;JS的基本语法
  5. 122FPS、51.8mAP 超轻量关键点检测算法PP-TinyPose来啦!
  6. 北斗授时服务器(GPS时钟服务器)在地铁轨道交通中的应用
  7. 怎样提高顾客的体验感?
  8. 【前端实例代码】如何使用 HTML 和 CSS 快速创建一个响应式导航栏
  9. Java黄金矿工小游戏,适合初学者练手项目_java游戏_java项目
  10. css图标代码 星,15个纯CSS实现的响应式土豪金星球类应用动画图标