Back to Underworld(搜索)
Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Description
The Vampires and Lykans are fighting each other to death. The war has become so fierce that, none knows who will win. The humans want to know who will survive finally. But humans are afraid of going to the battlefield.
So, they made a plan. They collected the information from the newspapers of Vampires and Lykans. They found the information about all the dual fights. Dual fight means a fight between a Lykan and a Vampire. They know the name of the dual fighters, but don't know which one of them is a Vampire or a Lykan.
So, the humans listed all the rivals. They want to find the maximum possible number of Vampires or Lykans.
Input
Input starts with an integer T (≤ 10), denoting the number of test cases.
Each case contains an integer n (1 ≤ n ≤ 105), denoting the number of dual fights. Each of the next n lines will contain two different integers u v (1 ≤ u, v ≤ 20000) denoting there was a fight between u and v. No rival will be reported more than once.
Output
For each case, print the case number and the maximum possible members of any race.
Sample Input
2
2
1 2
2 3
3
1 2
2 3
4 2
Sample Output
Case 1: 2
Case 2: 3
题解:两拨人打架,问最每队最大的可能人数是多少;搜索下。。。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
const int INF = 0x3f3f3f3f;
#define mem(x, y) memset(x, y, sizeof(x))
typedef long long LL;
void SI(int &x){scanf("%d", &x);}
void SI(LL &x){scanf("%lld", &x);}
const int MAXN = 1e5 + ;
int vis[MAXN], usd[MAXN];
int sum1, sum2;
vector<int>vec[MAXN];
void dfs(int i, int cur){
if(cur)sum1++;
else sum2++;
// vis[i] = 1;
for(int j = ; j < vec[i].size(); j++){
int v = vec[i][j];
if(vis[v])continue;
vis[v] = ;
dfs(v, cur ^ );
}
}
int main(){
int T,kase = , n;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
int x, y, tp = ;
for(int i = ; i <= MAXN; i++){
vis[i] = ;
usd[i] = ;
vec[i].clear();
}
for(int i = ; i < n; i++){
scanf("%d%d", &x, &y);
vec[x].push_back(y);
vec[y].push_back(x);
usd[x] = usd[y] = ;
tp = max(tp, x);
tp = max(tp, y);
}
int ans = ;
//printf("tp = %d\n", tp);
for(int i = ; i <= tp; i++){
if(vis[i] || !usd[i])continue;
sum1 = sum2 = ;
vis[i] = ;
dfs(i, );
// printf("%d %d %d \n", sum1,sum2,i);
ans += max(sum1, sum2);
}
printf("Case %d: %d\n", ++kase, ans);
}
return ;
}
Back to Underworld(搜索)的更多相关文章
- SQLSERVER走起微信公众帐号已经开通搜狗微信搜索
SQLSERVER走起微信公众帐号已经开通搜狗微信搜索 请打开下面链接 http://weixin.sogou.com/gzh?openid=oIWsFt-hiIb_oYqQHaBMoNwRB2wM ...
- solr_架构案例【京东站内搜索】(附程序源代码)
注意事项:首先要保证部署solr服务的Tomcat容器和检索solr服务中数据的Tomcat容器,它们的端口号不能发生冲突,否则web程序是不可能运行起来的. 一:solr服务的端口号.我这里的sol ...
- SQLServer地址搜索性能优化例子
这是一个很久以前的例子,现在在整理资料时无意发现,就拿出来再改写分享. 1.需求 1.1 基本需求: 根据输入的地址关键字,搜索出完整的地址路径,耗时要控制在几十毫秒内. 1.2 数据库地址表结构和数 ...
- HTML5轻松实现搜索框提示文字点击消失---及placeholder颜色的设置
在做搜索框的时候无意间发现html5的input里有个placeholder属性能轻松实现提示文字点击消失功能,之前还傻傻的在用js来实现类似功能... 示例 <form action=&quo ...
- bzoj1079--记忆化搜索
题目大意:有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块.所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n.相邻两个木块涂相同色显得 ...
- bzoj3208--记忆化搜索
题目大意: 花花山峰峦起伏,峰顶常年被雪,Memphis打算帮花花山风景区的人员开发一个滑雪项目. 我们可以把风景区看作一个n*n的地图,每个点有它的初始高度,滑雪只能从高处往低处滑[严格大于] ...
- Android中通过ActionBar为标题栏添加搜索以及分享视窗
在Android3.0之后,Google对UI导航设计上进行了一系列的改革,其中有一个非常好用的新功能就是引入的ActionBar,他用于取代3.0之前的标题栏,并提供更为丰富的导航效果.Action ...
- 一步步开发自己的博客 .NET版(5、Lucenne.Net 和 必应站内搜索)
前言 这次开发的博客主要功能或特点: 第一:可以兼容各终端,特别是手机端. 第二:到时会用到大量html5,炫啊. 第三:导入博客园的精华文章,并做分类.(不要封我) 第四:做 ...
- Go语言实战 - 我需要站内搜索
山坡网的用户抱怨"为什么搜索'二鬼子李富贵'找不到'二鬼子汉奸李富贵'?我用百度搜都能找到." 当时我就滴汗了,用户说的有道理,应该要能搜索到. 之前的方案很简单,用户输入的字串会 ...
随机推荐
- Jenkins动态部署方案
在之前一个项目开发中使用到了jenkins自动化测试,根据实际应用,简单整理了其部署方案. 1.部署 2.项目构建 3.重部署 1 部署 登录Jenkins应用管理界面 1)选中一个服务器上已在jen ...
- KafkaOffsetMonitor监控
介绍 KafkaOffsetMonitor是有由Kafka开源社区提供的一款Web管理界面,这个应用程序用来实时监控Kafka服务的Consumer以及它们所在的Partition中的Offset,你 ...
- zXing使用小结
在android上二维码.条形码扫描,google官方为我们提供了zXing,几乎android涉及到扫描的都是用这个开源项目实现的,也有在android上使用zBar的,和其他用过的交流得知zBar ...
- 学习Android之SharedPreferences使用
效果图例如以下: 当我们想让自己的属性设置保存下来,这时就须要SharedPreferences. 上面这个小程序,音乐状态是保存下来的.使用的上一次退出的状态. 进入DDMS,data文件下的dat ...
- oracle数据库recover和restore的区别
restore just copy the physical file, recover will consistent the database.restore 是还原,文件级的恢复.就是物理文件还 ...
- IoC容器Autofac之实例引入(一)
先不必尝试理解IOC,先来看段代码. 一.一个没有使用IoC的例子 public class MPGMovieLister { public Movie[] GetMPG() { var finder ...
- 在asp.net中导出表格Excel数据
第一步:需要引用org.in2bits.MyXls程序集到使用页面 第二步:前台代码 <asp:Button ID="LeadingOut" runat="serv ...
- javascript运动功能-分享到
<script> //窗体载入,为div控件绑定事件 window.onload = function () { var div1 = document.getElementById('d ...
- Nohttp请求图片的两种简答的方式:普通请求以及缓存请求
开局声明:这是基于nohttp1.0.4-include-source.jar版本写的教程 由于nohttp功能强悍,因此需要多种权限,仅仅一个联网的权限是不够的,如果只给了Internet的权限,去 ...
- UIImageView 一些属性设置
1.contentMode属性 这个属性是用来设置图片的显示方式,如居中.居右,是否缩放等,有以下几个常量可供设定: UIViewContentModeScaleToFill UIViewConten ...