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年開始,我就在思考轉行.之前在第一家企業接觸過一 ...
随机推荐
- Activity状态图、生命周期图(超详细),onSaveInstanceState只保存、恢复基本ui数据,持久数据不在这里保存。
1.Activity状态图 2.Activity生命周期简图 启动Activity: onCreate()—>onStart()—>onResume(),Activity进入running ...
- Android网络状态监控
Android 监控网络状态 在Android网络应用程序开发中,经常要判断网络连接是否可用,因此经常有必要监听网络状态的变化.android的网络状态监听可以用BroadcastReceiver来接 ...
- Oracle代码 规则 创建表 表空间 用户等
-----创建表空间----------create tablespace bdccslogging datafile 'D:\oracle\product\10.2.0\oradata\bdccs\ ...
- 468 Validate IP Address 验证IP地址
详见:https://leetcode.com/problems/validate-ip-address/description/ Java实现: class Solution { public St ...
- 【intellij idea】汇总
1 右键无法创建,找不到scala class https://blog.csdn.net/u011513853/article/details/52896230 2 缩进 https://jingy ...
- poj3662 Telephone Lines
思路: 二分+最短路.最短路也可以用来计算从a到达b所需的边权不超过x的边的数量. 实现: #include <cstdio> #include <cmath> #includ ...
- 初学者SQL shell(psql)无法登陆问题
因为项目第一次接触postgresql,有个问题搞死我了,如果初学,估计大家也会遇见这样的问题,希望可以节约时间. 用户postgres的口令不显示啊!服!
- python学习日记-01
一. 熟悉 在正式介绍python之前,了解下面两个基本操作对后面的学习是有好处的: (1)基本的输入输出 可以在Python中使用+.-.*./直接进行四则运算. >>> 1+3* ...
- PPTP的搭建
一.准备 1.检查是否支持pptp modprobe ppp-compress-18 && echo yes yes支持 2.是否开启tun cat /dev/net/tun 返回ca ...
- 迅为I.MX6Q开发板配不同分辨率不同尺寸液晶屏幕
I.MX6Q开发板: 核心板参数 尺寸:51mm*61mm iMX6Q四核CPU:Freescale Cortex-A9 四核 i.MX6Q,主频 1.2 GHz iMX6DL双核CPU:Freesc ...