HDU 5963 朋友(找规律博弈)
2024-08-25 14:55:32
http://acm.hdu.edu.cn/showproblem.php?pid=5963
题意:
思路:
我们可以先只考虑单链,自己试几种案例就可以发现规律,只有与根相连的边为1时,只需要奇数次操作,也就是1次就可以,而别的都需要偶数次操作才能把这条链上的边权全变成0,次数为$2^{n-1}$,n为边的层数。所以我们只要统计与根相连的有多少条权值为1的边即可。
需要改权值的时候搜索一下找到边然后修改。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn=+; int n, m;
vector<pll> G[maxn]; bool judge(int root)
{
int tmp=;
for(int i=;i<G[root].size();i++)
{
int v=G[root][i].first;
if(G[root][i].second==) tmp++;
}
if(tmp&) return true;
else return false;
} int main()
{
//freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) G[i].clear();
for(int i=;i<n;i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
G[u].push_back(make_pair(v,w));
G[v].push_back(make_pair(u,w));
}
while(m--)
{
int op, root;
scanf("%d",&op);
if(op==)
{
scanf("%d",&root);
if(judge(root)) puts("Girls win!");
else puts("Boys win!");
}
else
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
for(int i=;i<G[u].size();i++)
{
int vv=G[u][i].first;
if(vv==v) {G[u][i].second=w;break;}
}
for(int i=;i<G[v].size();i++)
{
int uu=G[v][i].first;
if(uu==u) {G[v][i].second=w;break;}
}
}
}
}
return ;
}
最新文章
- 在本地计算机无法启动MYSQL服务错误1067进程意外终止
- UWP源码——Unit Test
- C# 条码标签打印程序,RDLC报表动态显示多条码标签的方法
- 16_会话技术_Session
- IOS 笔试
- 12款免费与开源的NoSQL数据库
- python学习笔记3-列表
- 不同版本的IDE ,对应的选项 有变化
- C++中_cplusplus及Extern ";C";的理解
- JS--操作DOM树
- 404错误处理以及以后缀为action结尾的处理
- vue 上传图片 input=file
- Saiku的下载与安装(一)
- [LeetCode&;Python] Problem 292. Nim Game
- Hadoop日记系列目录
- Picasso处理同一url,但资源变了的情况
- #leetcode刷题之路21-合并两个有序链表
- Crossing Rivers HDU - 3232 (均匀分布)
- Hello Activemq
- spring 代理 演变过程
热门文章
- jmeter测试手机号码归属地
- Mac SVN版本从1.9降到1.8
- Bootstrap 网格系统(Grid System)的工作原理 - 媒体查询
- OAuth 白话简明教程 1.简述
- jQuery Mobile 和 Kendo UI 的比较(转)
- C/S模型之命名管道
- python3.4学习笔记(十二) python正则表达式的使用,使用pyspider匹配输出带.html结尾的URL
- php array 根据value获取key,in_array()判断是否在数组内实例
- 访问Hsql .data数据库文件
- Docker 的 Web 管理工具 DockerFly