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 ...
随机推荐
- MT【186】四边形中的余弦定理
在四边形$ABCD$中,若$AB=a,BC=b,CD=c,AD=d,AC=e,BD=f$,则 $$a^2c^2+b^2d^2=e^2f^2+2abcd\cos(A+C).$$ 注:这个结果可以看成是余 ...
- CF1025D Recovering BST
题意:给定序列,问能否将其构成一颗BST,使得所有gcd(x, fa[x]) > 1 解:看起来是区间DP但是普通的f[l][r]表示不了根,f[l][r][root]又是n4的会超时,怎么办? ...
- 【洛谷P1122】最大子树和
题目大意:给定一棵 N 个节点的无根树,点有点权,点权有正有负,求这棵树的联通块的最大权值之和是多少. 题解:设 \(dp[i]\) 表示以 i 为根节点的最大子树和,那么只要子树的 dp 值大于0, ...
- (转)在Eclipse中用TODO标签管理任务(Task)
背景:eclipse是一款功能十分强大的编辑,如果能够熟练运用,必定事半功倍,但如果不求甚解,无疑是给自己制造麻烦. 1 标签的使用 1.1 起因 如上图所示,在程序中有很多todo的标签出现,但是却 ...
- 将句子表示为向量(下):基于监督学习的句子表示学习(sentence embedding)
1. 引言 上一篇介绍了如何用无监督方法来训练sentence embedding,本文将介绍如何利用监督学习训练句子编码器从而获取sentence embedding,包括利用释义数据库PPDB.自 ...
- linux c 编程 ------ 串口编程
http://blog.csdn.net/specialshoot/article/details/50707965 对于串口的打开操作,必须使用O_NOCTTY参数.O_NOCTTY如果路径名指向终 ...
- java基础基础总结----- StringBuffer(重要)
前言StringBuffer:(常用的方法) StringBuffer与StringBuilder的区别 关于安全与不安全的解释:
- Linux命令dd与cp的区别
原文链接:http://blog.csdn.net/erazy0/article/details/6087554 问:看了一些关于dd和cp的命令,但是我始终无法明白dd和cp之间有什么不同?不是都可 ...
- properties编程示例
package com.lovo.props; import java.io.FileInputStream;import java.io.FileNotFoundException;import j ...
- Nginx ab压力测试
20-ab压力测试及nginx性能统计模块 优化的启发,打开的文件太多 Nginx 错误日志显示,打开文件数太多 系统层面 more /proc/sys/net/core/somaxconn 单个Ng ...