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 ...
随机推荐
- 上传文件到aws的s3存储
只要有aws-cli客户端就可以上传文件到aws的S3存储.可以在任意机器上.这里以centos为例. 1.安装python.pip. # yum install -y python python-p ...
- 解题:CF1055F Tree and XOR
题面 树上路径是可以通过到根的路径和LCA差出来的,所以建立一棵Trie树按位贪心即可......吗? 发现空间并不够,需要我们每层现建,要记录每个数和它异或答案之后在这一层插进去的编号 #inclu ...
- NO.6: 若不想编译器提供自动生成的函数,就应该明确拒绝
1.为驳回编译器自动生成函数的技能,可把这些函数的声明放入private,如果是继承类型可把base class的这些函数声明private,可在编译期间得到警告
- debian8.4 ibus中文输入法
安装IBus: # apt-get install ibus ibus-sunpinyin ibus-table-wubi 导入输入法: 在Activities->Applications-&g ...
- 风控模型-美国FICO标准
python信用评分卡(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_camp ...
- node.js+express,实现RESTful API
node代码如下(exptest.js): var express = require('express'); var bodyParser = require('body-parser'); var ...
- 启动MyEclipse8.5时未响应
错误原因: MyEclipse在进行编译时被强行关闭,就会编译内容出错. 解决方法: 1. 换个工作空间. 2. 寻找到工作空间那,访问到H:\javaWork5\.metadata\.plug ...
- JDK1.7安装和环境配置
进行Java或者Android开发,首先必须要搭建一个开发环境,先安装JDK,然后配置jdk环境变量.JDK现在的最高版本为JDK 1.8 ,如果我们要做Android开发,我们则需要JDK1.7以上 ...
- hdu 527 Necklace
http://acm.hdu.edu.cn/showproblem.php?pid=5727 阶乘 爆搜阴性宝石的排列,二分图最大匹配判断最多能使多少个阳性宝石不褪色 注: 1.O(n-1 !) 即可 ...
- Mysql select id 加上order by 后结果不一致
测试数据将近280万 1.SELECT id FROM cbbd ORDER BY id LIMIT 900000,10 2.SELECT id FROM cbbd LIMIT 900000,10 ...