Codeforces Round #284 (Div. 1) C. Array and Operations 二分图匹配
因为只有奇偶之间有操作, 可以看出是二分图, 然后拆质因子, 二分图最大匹配求答案就好啦。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int odd[N], even[N], ocnt, ecnt;
int L[N], R[N];
int G[N][N];
int match[N];
bool vis[N];
int n, m; int path(int u) {
for(int v = ; v <= ecnt; v++) {
if(G[u][v] && !vis[v]) {
vis[v] = true;
if(match[v] == - || path(match[v])) {
match[v] = u;
return ;
}
}
}
return ;
} int main() {
memset(match, -, sizeof(match));
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) {
int x;
scanf("%d", &x);
if(i & ) {
L[i] = ocnt + ;
for(int j = ; j * j <= x; j++) {
if(x % j) continue;
while(x % j == ) {
odd[++ocnt] = j;
x /= j;
}
}
if(x > ) odd[++ocnt] = x;
R[i] = ocnt;
} else {
L[i] = ecnt + ;
for(int j = ; j * j <= x; j++) {
if(x % j) continue;
while(x % j == ) {
even[++ecnt] = j;
x /= j;
}
}
if(x > ) even[++ecnt] = x;
R[i] = ecnt;
}
}
while(m--) {
int u, v; scanf("%d%d", &u, &v);
if(v & ) swap(u, v);
for(int i = L[u]; i <= R[u]; i++)
for(int j = L[v]; j <= R[v]; j++)
if(odd[i] == even[j]) G[i][j] = ;
}
int ans = ;
for(int i = ; i <= ocnt; i++) {
memset(vis, false, sizeof(vis));
if(path(i)) ans++;
}
printf("%d\n", ans);
return ;
} /*
*/
Codeforces Round #284 (Div. 1) C. Array and Operations 二分图匹配的更多相关文章
- Codeforces Round #284 (Div. 1) C. Array and Operations 二分图最大匹配
题目链接: http://codeforces.com/problemset/problem/498/C C. Array and Operations time limit per test1 se ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #284 (Div. 1)
A. Crazy Town 这一题只需要考虑是否经过所给的线,如果起点和终点都在其中一条线的一侧,那么很明显从起点走点终点是不需要穿过这条线的,否则则一定要经过这条线,并且步数+1.用叉积判断即可. ...
- Codeforces Round #181 (Div. 2) A. Array 构造
A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n ...
- Codeforces Round #535 (Div. 3) E2. Array and Segments (Hard version) 【区间更新 线段树】
传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit p ...
- Codeforces Round #284 (Div. 2)
题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...
- Codeforces Round #284 (Div. 1) A. Crazy Town 计算几何
A. Crazy Town 题目连接: http://codeforces.com/contest/498/problem/A Description Crazy Town is a plane on ...
- Codeforces Round #616 (Div. 2) B. Array Sharpening
t题目链接:http://codeforces.com/contest/1291/problem/B 思路: 用极端的情况去考虑问题,会变得很简单. 无论是单调递增,单调递减,或者中间高两边低的情况都 ...
- Codeforces Round #617 (Div. 3)A. Array with Odd Sum(水题)
You are given an array aa consisting of nn integers. In one move, you can choose two indices 1≤i,j≤n ...
随机推荐
- 【刷题】BZOJ 1023 [SHOI2008]cactus仙人掌图
Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人掌图(cactus).所谓简单回路就是指在图上不重复经过任何一个顶点的 ...
- 【BZOJ5281】Talent Show(分数规划)
[BZOJ5281]Talent Show(分数规划) 题面 BZOJ 洛谷 题解 二分答案直接就是裸的分数规划,直接跑背包判断是否可行即可. #include<iostream> #in ...
- bzoj2616: SPOJ PERIODNI——笛卡尔树+DP
不连续的处理很麻烦 导致序列DP又找不到优秀的子问题 自底向上考虑? 建立小根堆笛卡尔树 每个点的意义是:高度是(自己-father)的横着的极大矩形 子问题具有递归的优秀性质 f[i][j]i为根子 ...
- Git基本知识
一,安装 Ubuntu安装git:sudo apt-get install git-core Centos安装git:yum install git-core 二,配置身份---在提交代码时可以辨别身 ...
- git开发部署流程
git的分支操作 https://blog.csdn.net/QH_JAVA/article/details/77853605 Git 开发部署流程 采用业界成熟方案 Git Flow 分支方式进行开 ...
- k8s pod的4种网络模式最佳实战(externalIPs )
[k8s]k8s pod的4种网络模式最佳实战(externalIPs ) hostPort相当于docker run -p 8081:8080,不用创建svc,因此端口只在容器运行的vm ...
- 集合框架基础知识-----java基础知识
Java集合框架 :接口:Collection.List .Set. Map:实现类:ArrayList.LinkedList.Vector.HashSet.TreeSet.HashMap.HashT ...
- java基础基础总结----- 随机数(产生四个随机数)
前言:在开发的时候经常会遇见,一些验证码登录,其实这些东西,很简单.我曾经开发过一个验证码登录的页面,那时用的插件.但是作为一个合格的开发者,要了解其内部的核心知识,有些东西,可以不深入了解,但是要做 ...
- 流媒体技术学习笔记之(七)进阶教程OBS参数与清晰度流畅度的关系
源码地址:https://github.com/Tinywan/PHP_Experience 很多主播问过OBS的参数到底什么影响画质,到底什么影响流畅度,那么本篇教程尽量用通俗的语言解释下一些重要参 ...
- 干货:制作科研slide简明规范