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 ...
随机推荐
- COCI 2018/2019 CONTEST #2 Solution
Problem1 Preokret 第一题一定不是什么难题. 第一个问题在读入的时候判断当前时间是不是在1440及以前就行 第二个问题考虑离线处理,由于每个时刻只能最多发生1个事件那么就弄个桶记录每一 ...
- Path Sum II - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Path Sum II - LeetCode 注意点 不要访问空结点 解法 解法一:递归,DFS.每当DFS搜索到新节点时,都要保存该节点.而且每当找出一 ...
- adb相关基础知识集锦
Android单元测试adb shell am instrument -w adb shell dumpsys adb logcat介绍
- 使用 python 自动打包 Android 和 iOS
https://github.com/jinzunyue/package-Android-and-iOS
- 论攻击Web应用的常见技术
攻击目标: 应用HTTP协议的服务器和客户端.以及运行在服务器上的Web应用等. 攻击基础: HTTP是一种通用的单纯协议机制.在Web应用中,从浏览器那接受到的HTTP请求的全部内容,都可以在客户端 ...
- chrome 隐藏技能之 base64 图片转换
有时候我们要转换图片为base64,或者将base64转回图片,可能都需要找一些在线工具或者软件类型的工具才行.当然 chrome 也算是软件,但是好在做前端的都有 chrome.好了,来看下简单的例 ...
- 从零开始编写自己的JavaScript框架(一)
1. 模块的定义和加载 1.1 模块的定义 一个框架想要能支撑较大的应用,首先要考虑怎么做模块化.有了内核和模块加载系统,外围的模块就可以一个一个增加.不同的JavaScript框架,实现模块化方式各 ...
- CSSOM
概要 狭义的 DOM API 仅仅包含 DOM 树形结构相关的内容. DOM 中的所有的属性都是用来表现语义的属性,CSSOM 的则都是表现的属性. CSSOM 是 CSS 的对象模型,在 W3C 标 ...
- WordPress中使用Markdown和Syntax Highlighter
下载安装插件 在wordpress插件中安装WP Code Prettify. PHP Markdown Extra 下载Extra,并上传安装到wordpress. Code Prettify th ...
- Linux中普通用户提权为超级用户
首先创建一个普通用户,并且给普通用户设置一个密码,保证能用su 命令能用普通用户登录 [root@ahu ~]# useradd test [root@ahu ~]# passwd test New ...