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题,离散化和树状数 ...
随机推荐
- Swift - 推送之本地推送(UILocalNotification)添加Button的点击事件
上一篇讲到的本地推送是普通的消息推送,本篇要讲一下带按钮动作的推送消息 import UIKit @UIApplicationMain class AppDelegate: UIResponder, ...
- Cocoapods的安装报错 - Error installing pods:activesupport requires Ruby version >=2.2.2
1.打开终端 2 移除现有 Ruby 默认源 输入以下指令 $gem sources --remove https://rubygems.org/ 3.使用新的源 输入以下指令 $gem source ...
- iOS源码之OC相册,可以循环查看图片
#import "ViewController.h" #import "YZUIScrollView.h" #define kuan ([UIScreen ma ...
- PHP超全局变量
PHP提供了九种超全局变量(数组) 1 $_GET //地址栏上获得的值 2 $_POST //POST表单发送的数据 3 $_REQUEST //GET和POST的内容全都有 4 $_SERVER ...
- php JS和JQ
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- BlueTooth: 蓝牙基础知识进阶——链路控制操作
转自:http://blog.csdn.net/augusdi/article/details/25887395 七链路控制操作 链路控制操作就是用来描述一个设备是如何加入piconet又是如何从一个 ...
- Delphi面向对象的属性
可以把属性看成是能对类中的数据进行修改和执行代码的特殊的辅助域.对于组件来说,属性就是列在Object Inspector窗口的内容.下面的例子定义了一个有属性的简单对象 TMyObject = cl ...
- 【Java EE 学习 19】【使用过滤器实现全站压缩】【使用ThreadLocal模式解决跨DAO事务回滚问题】
一.使用过滤器实现全站压缩 1.目标:对网站的所有JSP页面进行页面压缩,减少用户流量的使用.但是对图片和视频不进行压缩,因为图片和视频的压缩率很小,而且处理所需要的服务器资源很大. 2.实现原理: ...
- 【JAVA正则表达式综合练习】
一.治疗口吃. 将字符串“我我我我我我我..........我.......要要要要要..................要要要要...学习习习习.......习习习习习习习习编程程程程程程..... ...
- 学习SQLAlchemy Core
有时间了就要慢慢看,死守DJANGO ORM,明显没有SQLAlchemy有优势. 因为SQLAlchemy针对整个PYTHON都是有用的. 找了本书,慢慢撸. <Essential.SQLAl ...