The 2015 China Collegiate Programming Contest E. Ba Gua Zhen hdu 5544
Ba Gua Zhen
Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 304 Accepted Submission(s): 93
Fortunately, there was an old man named Chengyan Huang who was willing to help Xun Lu to hack the puzzle. Chengyan told Xun Lu that he had to choose a vertex as the start point, then walk through some of the edges and return to the start point at last. During his walk, he could go through some edges any times. Since Liang Zhuge had some mysterious magic, Xun Lu could hack the puzzle if and only if he could find such a path with the maximum XOR sum of all the edges length he has passed. If the he passed some edge multiple times, the length would also be calculated by multiple times. Now, could you tell Xun Lu which is the maximum XORcircuit path in this puzzle to help him hack the puzzle?
Each test case begins with two integers N(2≤N≤5×104) and M(1≤M≤105) in one line. Then M lines follow. Each line contains three integers ui, viand wi(1≤ui,vi≤N,0≤wi≤260−1) to describe all the edges in the puzzle.
3 3
1 2 1
1 3 2
2 3 0
6 7
1 2 1
1 3 1
2 3 1
3 4 4
4 5 2
4 6 2
5 6 2
Case #2: 3
A XOR takes two bit patterns of equal length and performs the logical exclusive OR operation on each pair of corresponding bits.
The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1.
In this we perform the comparison of two bits, being 1 if the two bits are different, and 0 if they are the same.
分析:可以拆成几个简单环来做,这样做就不会有问题。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<functional>
#include <cassert>
using namespace std;
typedef long long LL; const int maxn = ;
const int maxm = ;
struct node {
int nex;
}a[maxn];
struct edge {
int nex, y;
LL v;
}e[maxm];
int p;
long long stack[maxn];
int top;
int tot;
int f[maxn];
long long num[];
void add(int X, int Y, LL V) {
p++;
e[p].nex = a[X].nex;
e[p].v = V;
a[X].nex = p;
e[p].y = Y;
}
bool vis[maxn];
void dfs(int x) {
f[x] = ++top;
vis[x] = true;
for (int t = a[x].nex; t; t = e[t].nex) {
int y = e[t].y; if (f[y] == ) {
stack[y] = stack[x] ^ e[t].v;
dfs(y);
}else {
if (!vis[y]) continue;
num[++tot] = stack[x] ^ e[t].v ^ stack[y];
//cout << x << " " << num[tot] << " " << s << " " << y << endl;
}
}
vis[x] = false;
} LL b[], bN;
void solve() {
bN = ;
// swap(num[3], num[2]);
for (int i = ; i <= tot; ++ i) {
// printf("%lld\n", num[i]);
for (int j = ; j < bN; ++ j) {
if ((num[i]^b[j]) < num[i])
num[i] = num[i] ^ b[j];
}
if (num[i])
b[bN ++] = num[i];
} sort(b, b+bN, greater<LL>());
// for (int i = 0; i < bN; ++ i) printf("%lld ", b[i]); LL res = ;
for (int i = ; i < bN; ++ i)
if ((res ^ b[i]) > res)
res ^= b[i];
printf("%I64d\n", res);
// printf("%lld\n", res);
} int T, cas = , n, m;
int main() {
// freopen("e.in","r",stdin);
scanf("%d", &T);
while (T--) {
printf("Case #%d: ", ++cas);
scanf("%d%d", &n, &m);
p = ;
memset(a,,sizeof(a));
memset(e,,sizeof(e));
for (int i = ; i <= m; i++) {
int x, y; LL v;
scanf("%d%d", &x, &y);
// scanf("%lld", &v);
scanf("%I64d", &v);
add(x, y, v);
add(y, x, v);
}
memset(stack,,sizeof(stack));
top = ;
tot = ;
memset(vis,,sizeof(vis));
memset(f,,sizeof(f));
dfs();
//for (int i = 1; i <= tot; i++) cout << num[i] << endl;
sort(num+, num++tot); tot = unique(num+, num++tot) - (num+);
// for (int i = 1; i <= tot; i++) cout << num[i] << endl;
solve();
}
return ;
}
The 2015 China Collegiate Programming Contest E. Ba Gua Zhen hdu 5544的更多相关文章
- The 2015 China Collegiate Programming Contest L. Huatuo's Medicine hdu 5551
Huatuo's Medicine Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- The 2015 China Collegiate Programming Contest D.Pick The Sticks hdu 5543
Pick The Sticks Time Limit: 15000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540
Secrete Master Plan Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- The 2015 China Collegiate Programming Contest Game Rooms
Game Rooms Time Limit: 4000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- The 2015 China Collegiate Programming Contest C. The Battle of Chibi hdu 5542
The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- The 2015 China Collegiate Programming Contest K Game Rooms hdu 5550
Game Rooms Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- The 2015 China Collegiate Programming Contest H. Sudoku hdu 5547
Sudoku Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
- The 2015 China Collegiate Programming Contest G. Ancient Go hdu 5546
Ancient Go Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- The 2015 China Collegiate Programming Contest -ccpc-c题-The Battle of Chibi(hdu5542)(树状数组,离散化)
当时比赛时超时了,那时没学过树状数组,也不知道啥叫离散化(貌似好像现在也不懂).百度百科--离散化,把无限空间中无限的个体映射到有限的空间中去,以此提高算法的时空效率. 这道题是dp题,离散化和树状数 ...
随机推荐
- GTID复制之二
在线启用GTID,这样就不会对生产造成影响. 1.在每个Server上,执行 SET @@GLOBAL.ENFORCE_GTID_CONSISTENCY=WARN;确保在ErrorLog中没有WARN ...
- 经典.net试题
经典.net面试题目 1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . private : 私有成员, 在类的内部才可以访问. pr ...
- AFNetworking(AFN)总结
AFNetworking(AFN) ----主要做下载上传之用 //他是干啥的?发送请求,主要做下载上传之用 (苹果自带有获取服务器数据的方法NSURLConnection send,AFNetwor ...
- TCP/IP五层模型
(2)TCP/IP五层模型的协议 应用层 传输层 网络层 数据链路层 物理层 物理层:中继器.集线器.还有我们通常说的双绞线也工作在物理层 数据链路层:网桥(现已很少使用).以太网交换机(二层 ...
- php基础面试题1
问题1:谈谈你对的PHP的基本认识. 回答:PHP是Hypertext Preprocessor(超文本预处理器)的简称,是一种用来开发动态网站的服务器端脚本语言. 问题2:什么是MVC? 回答:MV ...
- 浅谈我的编程之路——感谢引领我的leader
在开发的道路上,就始终无法避开版本控制,哪怕你是独自一人进行开发,版本控制也是有必要的,从最早开始使用CVS,到后来使用SVN,再到git,最后又回到了SVN,但是不知道为什么真的对SVN很无爱. 现 ...
- AJAX 汽车详细信息练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- sql server 的cpu使用率过高的分析
有哪些SQL语句会导致CPU过高? 1.编译和重编译 编译是 Sql Server 为指令生成执行计划的过程.Sql Server 要分析指令要做的事情,分析它所要访问的表格结构,也就是生成执行计划的 ...
- Git撤销提交和修改相关操作
团队开发中经常遇到错误删除文件,错误提交等情况,那么使用Git该如何正确的进行撤销和恢复呢? 一.增补提交 git commit –C HEAD –a --amend -C表示复用指定提交的提交留言, ...
- 关于Java反射机制的几个问题
>>如何在运行时确定对象类型 运行时类型识别(Run-time Type Identification, RTTI)主要有两种方式, 一种是在编译时和运行时已经知道了所有的类型,另外一种是 ...