JZOJ 5777. 【NOIP2008模拟】小x玩游戏
5777. 【NOIP2008模拟】小x玩游戏
(File IO): input:game.in output:game.out
Description
但小x遇到了难题。他不知道自己的队友是谁。他只知道总共有两个队伍,每队有n个人和很多组击杀情况。他想问你,现在他能否知道两个队伍分别有谁。你可以帮助小x吗?由于小x是个游戏狂魔,所以他玩了很多局游戏。
Input
接下来有t组数据,每组数据第一行有一个n,m,表示每队有n个人,有m组击杀情况,接下来m行每行两个字符串s1,s2,表示s1杀了s2,其中s1,s2的长度均不超过10(数据保证两个字符串都由小写字母组成)。注意一个人可以被击杀多次、一个人可以被曾经杀死过的人给杀死。
Output
Sample Input
1
2 3
a b
c d
a d
Sample Output
YES 样例解释:
a,c是一队,b,d是一队。
Data Constraint
对于30%的数据,n<=1000,m<=10000;
对于100%的数据,t<=10,n<=2000,m<=100000。
数据保证不会有矛盾的关系。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#define MO 10000000009
#define mo 233437
#define LL long long
using namespace std;
LL t, n, m, ls[mo + ], tot, cnt, A, B;
struct arr
{
int to, next;
}e[mo];
string st;
bool b[mo + ];
LL h[mo + ];
LL H[]; void Add(int x, int y)
{
e[++cnt].to = y;
e[cnt].next = ls[x];
ls[x] = cnt;
} LL Hash(LL p)
{
int g = p % mo;
for (; h[g] != && h[g] != p; g = (g + ) % mo);
return g;
} void Init()
{
scanf("%d%d", &n, &m);
for (int i = ; i <= m; i++)
{
cin >> st;
LL u = , v = , t1, t2;
memset(H, , sizeof(H));
for (int i = ; i < st.size(); i++)
H[i + ] = ((H[i] + st[i] - 'a' + ) * ) % MO;
u = H[st.size()];
v = Hash(u);
h[v] = u;
t1 = v;
memset(H, , sizeof(H));
cin >> st;
for (int i = ; i < st.size(); i++)
H[i + ] = ((H[i] + st[i] - 'a' + ) * ) % MO;
u = H[st.size()];
v = Hash(u);
h[v] = u;
t2 = v;
Add(t1, t2);
Add(t2, t1);
}
} void Dfs(int x, int D)
{
if (D) A++;
else B++;
for (int i = ls[x]; i; i = e[i].next)
{
if (b[e[i].to]) continue;
b[e[i].to] = ;
Dfs(e[i].to, D ^ );
}
} void Work()
{
A = , B = ;
int j = ;
while (!h[j]) j++;
b[j] = ;
Dfs(j, );
if ((A & B & n) == n)
{
printf("YES\n");
return;
}
printf("NO\n");
return;
} int main()
{
freopen("game.in", "r", stdin);
freopen("game.out", "w", stdout);
scanf("%d", &t);
for (; t; t--)
{
memset(ls, , sizeof(ls));
memset(e, , sizeof(e));
memset(b, , sizeof(b));
memset(h, , sizeof(h));
cnt = ;
Init();
Work();
}
}
JZOJ 5777. 【NOIP2008模拟】小x玩游戏的更多相关文章
- 2783: 【基础】小 X 玩游戏(game)
2783: [基础]小 X 玩游戏(game) 时间限制: 1 Sec 内存限制: 64 MB 提交: 752 解决: 294 [提交] [状态] [讨论版] [命题人:ghost79] 题目描述 听 ...
- P5676 [GZOI2017]小z玩游戏【Tarjan】
小z玩游戏 Tarjan算是板子题吧,但是要稍微做一些修改,建边需要多考虑,建立"虚点". 题目描述 小 z 很无聊. 小 z 要玩游戏. 小 z 有\(N\)个新游戏,第\(i\ ...
- P5676 [GZOI2017]小z玩游戏 Tarjan+优化建图
题目描述 分析 一开始看到这道题,首先想到的就是建好边后跑一个Tarjan缩点,将siz大于1的节点统计一下,输出结果 Tarjan非常显然易得,关键就是怎么建边 比较好想的一种思路就是枚举每一个兴奋 ...
- 【题解】 [GZOI2017]小z玩游戏
题目戳我 \(\text{Solution:}\) 考虑建图.操作可以看作对\(1\)进行的操作,于是有以下运行过程: \(1\to w[i]\to e[i]\to...\) 考虑倍数,一个数可以走到 ...
- SCUT - 131 - 小P玩游戏II - 贪心 - 平衡树
https://scut.online/p/131 首先假如钦定了一群人去打怪兽,那么可以把主要的任务都丢给b最大的人去打,这样不会更差.然后考虑枚举这个b最大的人,其他人陪练.一开始就是ai+k*b ...
- 神奇的建图方式(Tarjan)——小z玩游戏
原题来自与:洛谷 P5676(GZOI2017) 链接: https://www.luogu.com.cn/problem/P5676 题面: 题意比较明显,如果已经建好了边,那么跑个Tarjan ...
- J - 玩游戏
小A和小B玩游戏,初始的时候小A给小B一组包含n个数的数组.他们按如下的规则进行: 每次小B得到一组数,他把这组数的和加到自己的分数里面(他的初始分数是0),然后他把这组数还给小A. 如果小A得到的这 ...
- JZOJ 5793. 【NOIP2008模拟】小S练跑步
5793. [NOIP2008模拟]小S练跑步 (File IO): input:run.in output:run.out Time Limits: 2000 ms Memory Limits: ...
- JZOJ 5776. 【NOIP2008模拟】小x游世界树
5776. [NOIP2008模拟]小x游世界树 (File IO): input:yggdrasil.in output:yggdrasil.out Time Limits: 1500 ms Me ...
随机推荐
- D. Time to Raid Cowavans 分块暴力,感觉关键在dp
http://codeforces.com/contest/103/problem/D 对于b大于 sqrt(n)的,暴力处理的话,那么算出每个的复杂度是sqrt(n),就是把n分成了sqrt(n)段 ...
- 二进制读取 jdbc
package com.itheima.clob.test; import java.io.FileInputStream; import java.io.FileOutputStream; impo ...
- java里如何实现循环打印出字符或字符数组里的内容
不多说,直接上干货! java里如何实现循环打印出字符里的内容 没写,暂时不会 java里如何实现循环打印出字符数组里的内容 public class test { public static voi ...
- Spring那些不得不知的细节
1.SpringMVC拦截器的url-pattern和RequestMapping 案例: url-pattern为/rest/* http请求为:/rest/query/id 那么requestMa ...
- Cause: java.sql.SQLException: 无法转换为内部表示(Mybatis)
公司开发档案系统使用框架:Spring+Struts2+Mybatis+EasyUI,在开发过程中出现sql异常:“Cause: java.sql.SQLException: 无法转换为内部表示”,错 ...
- Struts2 源码分析-----Hello world
今天第一天学习struts2,没学过怎么办,那当然是helloworld.感觉嘛,学习的基本流程都差不多,就是helloworld,开发环境,然后就是逐个按照知识点打demo,打着打着你就会发现str ...
- JS中关于clientWidth offsetWidth scrollWidth 等的区别
网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...
- <Android 应用 之路> 天气预报(四)
前言 第二次尝试完成天气预报应用,与上次不同的是,个人感觉这次的Ui不那么丑陋,整体的实用性和界面效果,用户体验相较上一次有所提升,但是还是有很多地方需要完善. 这次使用到的内容比较丰富,包括聚合数据 ...
- Oracle Form个性化案例(一)
业务场景: 现有Form A,需通过A中的菜单栏中调用另一Form B,需将某值作为参数传入Form B中:
- zabbix-3.4-服务监控
服务监控 总览 服务监控(services monitoring)旨在帮助那些想要高级(业务)基础设施的监控的人.在许多情况下,我们关注的不是底层细节,比如磁盘空间不足.CPU 负载高等.我们关注的是 ...