poj 1182用向量的思考模式
不会写果断看答案http://cavenkaka.iteye.com/blog/1489588
#include<stdio.h>
#include<string.h>
#define N 50010
int father[N],link[N];
int find(int x) {
if(x!=father[x]) {
int h=father[x];
father[x]=find(father[x]);
link[x]=(link[x]+link[h])%3;
}
return father[x];
}
void insert(int x,int y,int d) {
int xx=find(x);
int yy=find(y);
father[xx]=yy;
link[xx]=(link[y]-link[x]+3+d)%3;
}
int main() {
int n,k,i,m,a,b,c,f1,f2;
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++)
father[i]=i;
memset(link,0,sizeof(link));
m=0;
while(k--) {
scanf("%d%d%d",&a,&b,&c);
if(b>n||c>n||(a==2&&b==c)) {
m++;
continue;
}
f1=find(b);
f2=find(c);
if(f1==f2) {
if((link[b]-link[c]+3)%3!=a-1)
m++;
}
else
insert(b,c,a-1);
}
printf("%d\n",m);
return 0;
}
poj 1182用向量的思考模式的更多相关文章
- POJ 1182 食物链 (带权并查集 && 向量偏移)
题意 : 中文题就不说题意了…… 分析 : 通过普通并查集的整理归类, 能够单纯地知道某些元素是否在同一个集合内.但是题目不仅只有种类之分, 还有种类之间的关系, 即同类以及吃与被吃, 而且重点是题目 ...
- POJ 1182 食物链(种类并查集)
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 63592 Accepted: 18670 Description ...
- poj 1182:食物链(种类并查集,食物链问题)
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44168 Accepted: 12878 Description ...
- POJ 1182 食物链
G - 食物链 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- 食物链 poj 1182
C - 食物链 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- poj 1182 食物链 (带关系的并查集)
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44835 Accepted: 13069 Description 动 ...
- POJ 1182——食物链——————【种类并查集】
食物链 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit Status P ...
- POJ 1182 食物链 [并查集 带权并查集 开拓思路]
传送门 P - 食物链 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit ...
- 淺談Coach思考模式
我現在是個窮屌,沒錯.我清楚的知道這一點,但是我也知道,我能改變. 之前幹了7年的評估行業,中間換了3家公司,第一家公司待的時間最長,待了5年.2018年開始,我就在思考轉行.之前在第一家企業接觸過一 ...
随机推荐
- 关于Swing中JFrame等顶级容器的层次还有设置背景的方式
资料来自:http://blog.csdn.net/qq_32006373/article/details/49659129 http://yuncode.net/code/c_5196327caac ...
- Android系统的启动流程
手机启动后首先会通过执行BootLoader来启动Linux内核,BootLoader是所有嵌入式设备开机启动执行的第一行代码,linux内核在启动过程中会加载各种设备的驱动同时初始化数据结构,并且开 ...
- Rsync 12种故障排查及思路
Rsync 故障排查整理 Rsync服务常见问题汇总讲解: ====================================================================== ...
- .Net应用自定义鼠标样式
(调用系统API的方法) 1.引用命名空间 using System.Runtime.InteropServices; 命名空间提供各种各样支持 COM 互操作 及平台调用服务的成员.using Sy ...
- .NET通过字典给类赋值
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam& ...
- Swiper插件轮播
<html><head> <meta charset="utf-8"> <title>Swiper轮播</title>& ...
- 用vue写的移动端车牌号输入法
效果图: (录制了视频演示,然而不会上传.....心塞.....) 本页面所在项目已上传GitHub,github下载地址:https://github.com/dan-Zd/car-vueapp ...
- Compiler 1.6.5 —1.6.7
Compiler 1.6.5 —1.6.7 Dynamic Scope Technically, any scoping policy is dynamic if it is based on fa ...
- webpack2版本四个核心概念
webpack 是一个现代的 JavaScript 应用程序的模块打包器(module bundler) 四个核心概念: --------------------------------------- ...
- ZooKeeper系列(三)
前面虽然配置了集群模式的Zookeeper,但是为了方面学建议在伪分布式模式的Zookeeper学习Zookeeper的shell命令. 一.Zookeeper的四字命令 Zookeeper支持某些特 ...