UVALive 6340 Gandalf vs the Balrog(超坑)
发布日期:2021-11-06 16:56:34 浏览次数:2 分类:技术文章

本文共 3804 字,大约阅读时间需要 12 分钟。

Gandalf vs the Balrog
Time Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu

Description

'We fought far under the living earth, where time is not counted. Ever he clutched me, and ever I hewed him, till at last he fled into dark tunnels.Ever up now we went, until we came to the Endless Stair. Out he sprang, and even as I came behind, he burst into new flame.Those that looked up from afar thought that the mountain was crowned with storm. Thunder they heard, and lightning, they said, smote upon Celebdil, and leaped back broken into tongues of fire.'
- Gandalf, describing his fight against the Balrog.

Although Gandalf would not go into the details of his battle, they can be summarized into the following simplified form: both Gandalf and the Balrog have a set of N attacks they can use (spells, swords, brute-force strength etc.). These attacks are numbered from 1 to N in increasing order of Power. When each has chosen an attack, in general, the one with the higher power wins. However, there are a few (M) anomalous pairs of attacks, in which the lesser-powered attack wins.

Initially, Gandalf picks an attack. Then the Balrog counters it with one of the remaining attacks. If the Balrog's counter does not defeat Gandalf's, then we say Gandalf receives a score of 2. If however it does, then Gandalf has exactly one more opportunity to pick an attack that will defeat the Balrog's. If he manages to defeat him now, his score will be 1, whereas if he is still unable to defeat him, his score will be 0.

Your task is to determine, given N and the M anomalous pairs of attacks, what will be Gandalf's score, given that both play optimally. Further, in case Gandalf gets a score of 2, you must also determine which attack he could have chosen as his first choice.

Note 1: The Balrog can choose only one attack, whereas Gandalf can choose upto two.
Note 2: The relation A defeats B is not transitive within the attacks.For example, attack A can defeat attack B, attack B can defeat attack C, and attack C can defeat attack A.
Note 3: Between any two attacks A and B, either attack A defeats attack B or attack B defeats attack A.

Input

The first line will consist of the integer T, the number of test-cases.

Each test case begins with a single line containing two integers N and M.This is followed by M lines consisting of 2 integers each x and y, denoting that x and y are an anomalous pair.

Output

For each test-case, output a single line either

2 A, if Gandalf can defeat any attack the Balrog chooses if he picks attack A,
1, if Gandalf can choose an attack such that even if the Balrog chooses an attack to defeat him, he can choose an attack to defeat the Balrog's chosen card,
0, if none of the above two options are possible for all possible choices of Gandalf's attack(s).Between successive test cases, there should not be any blank lines in the output.

Constraints:
1<=T<=15
3<=N<=1, 000, 000
0<=M<=min(N(N - 1)/2, 300, 000)
1<=x <= y<N for all the anomalous pairs (x, y)
The sum of M over all test-cases will not exceed 300,000.

Notes/Explanation of Sample Input:

In the first case, attack 3 can beat both attacks 1 and 2. So Gandalf just chooses attack 3.

In the second case, attack 1 beats 3 which beats 2 which beats 1. No matter which attack Gandalf chooses, the Balrog can pick the one which defeats his, but then he can pick the remaining attack and defeat the Balrog's.

Sample Input

23 03 11 3

Sample Output

2 31

AC代码:

#include 
#include
#define Max 1000005//author:XXYYint a[Max];int main(){ int n,i,j,t,m,x,y; scanf("%d",&t); while(t--){ memset(a,0,sizeof(a)); scanf("%d%d",&n,&m); if(m==0) printf("2 %d\n",n); else{ for(i=0;i
0;i++){ if(!a[i]) break; } if(i==n) printf("2 %d\n",n); else printf("1\n"); } } return 0;}

转载地址:https://blog.csdn.net/YJX_xx/article/details/37362581 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:UVALive 6342 The Mirror of Galadriel (回文串)
下一篇:DFS-BFS搜索专题【经典训练题】【有时间一个个做下来】

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月26日 19时20分30秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

北斗导航 | GNSS卫星导航天线在车载高精度定位领域中的应用与挑战 2019-04-28
北斗导航 | GNSS技术在自动驾驶中的作用 2019-04-28
北斗导航 | RAIM接收机自主完好性检测(附代码) 2019-04-28
北斗导航 | 学习PPP和PPP-RTK 2019-04-28
北斗导航 | 基于RTK的GNSS与多源融合定位技术发展与挑战 2019-04-28
安装 | 最新MATLAB 2020b(64位)安装教程完整版 2019-04-28
北斗导航 | 微惯导定位系统关键技术与应用 2019-04-28
北斗导航 | PPP-RTK技术研究进展与试验验证(第十一届中国卫星导航年会报告) 2019-04-28
北斗导航 | 北斗/GNSS精密定位:从PPP-RTK 到 Vision-PPP(第十一届中国卫星导航年会报告) 2019-04-28
北斗导航 | 多GNSS系统PPP-RTK原型系统及性能分析(2020 CPGPS全球华人导航定位协会年会) 2019-04-28
计算机视觉与深度学习 | 不含动态背景的前景目标提取 2019-04-28
计算机视觉与深度学习 | 动态背景下的前景目标提取 2019-04-28
《数据“科学家”必读》 | 从零起步打造数字化业务「最强大脑」 2019-04-28
好消息!Azure Active Directory 域服务在中国区正式发布! 2019-04-28
《数据“科学家”必读》 | 与Cosmos DB实现数据同步 2019-04-28
官宣:在微软智能云 Azure 上可以部署红帽 OpenShift 啦,快来康康怎么操作 2019-04-28
以己之盾,御彼之矛——你需要知道的安全总览浅析 2019-04-28
毕业十年即登全球副总裁,微软的这个后浪有点强 2019-04-28
云基础架构采用者避坑指南:拥抱“云”,更懂“云” 2019-04-28
《数据“科学家”必读》 | 创建自动化的数据处理水线 2019-04-28