题目大意是

给出L,H      10^10范围

为[L, H]这个连续的整数区间寻找一个序列。

序列的长度要跟[L, H]一样

然后序列中的数都是素数,并且互不相同

并且序列中第i个数 要求是L + i -1的一个素因子

最后要求序列的字典序最小

然后可以看到L,H很大

但是我们需要注意的是,这个序列长度肯定不会很大

太大了肯定满足不了题目的要求。

所以这个整数区间的数我们可以一个一个的,先把每个数都素因子分解了,放起来。

然后就发现。 这不就是二分图匹配么。

但是题目求的是字典序最小。

所以我们就对每个数。

对其所有的素因子,尝试改变匹配,然后寻找增广路。

如果能找到。就固定这条边

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#define MAXN 111111
#define N 505
using namespace std;
bool tag[MAXN];
int p[MAXN];
int cnt;
int mark[5555], used[5555];
int cx[N], cy[5555];
vector<int>g[N];
int ans[N];
int m, up;
long long l, r;
long long a[MAXN];
set<long long>s;
map<long long, int> id;
void getprime()
{
cnt = 0;
tag[1] = 1;
for(int i = 2; i < 100000; i++)
{
if(!tag[i]) p[cnt++] = i;
for(int j = 0; j < cnt && p[j] * i < 100000; j++)
{
tag[i * p[j]] = 1;
if(i % p[j] == 0) break;
}
}
}
void get(long long x)
{
for(int i = 0; i < cnt && x >= (long long)p[i] * (long long)p[i]; i++)
if(x % p[i] == 0)
{
s.insert(p[i]);
while(x % p[i] == 0) x /= p[i];
}
if(x != 1)
s.insert(x);
}
void get2(long long x)
{
long long tx = x;
for(int i = 0; i < cnt && x >= (long long)p[i] * (long long)p[i]; i++)
if(x % p[i] == 0)
{
long long tmp = (long long)p[i];
while(x % tmp == 0) x /= tmp;
g[tx - l + 1].push_back(id[tmp]);
}
if(x != 1)
g[tx - l + 1].push_back(id[x]);
}
int path(int u)
{
int sz = g[u].size();
for(int i = 0; i < sz; i++)
{
int v = g[u][i]; if(!mark[v] && !used[v])
{
mark[v] = 1;
if(cy[v] == -1 || path(cy[v]))
{
cx[u] = v;
cy[v] = u;
return 1;
}
}
}
return 0;
} bool ok(int t)
{
memset(cy, -1, sizeof(cy));
for(int i = t + 1; i <= up; i++)
{
memset(mark, 0, sizeof(mark));
if(!path(i)) return false;
}
return true;
}
void fix()
{
for(int i = 1; i <= up; i++)
{
int sz = g[i].size();
for(int j = 0; j < sz; j++)
{
int v = g[i][j];
if(used[v]) continue;
cx[i] = v;
used[v] = 1;
if(!ok(i)) used[v] = 0;
else break;
}
used[cx[i]] = 1;
}
}
void out(long long a )
{
if(a >= 10) out(a / 10);
putchar('0' + a % 10);
}
int main()
{
getprime(); while(scanf("%lld%lld", &l, &r) != EOF)
{
if(l == 0 && r == 0) break;
s.clear();
id.clear();
up = r - l + 1;
for(int i = 1; i <= up; i++) g[i].clear();
memset(ans, -1, sizeof(ans));
memset(used, 0, sizeof(used));
m = 0;
for(long long i = l; i <= r; i++)
get(i);
for(set<long long>::iterator it = s.begin(); it != s.end(); it++)
{
a[m++] = *it;
id[a[m - 1]] = m;
}
for(long long i = l; i <= r; i++)
get2(i);
fix();
for(int i = 1; i < up; i++)
{
//printf("%lld ", a[cx[i] - 1]);
out(a[cx[i] - 1]);
putchar(' ');
}
out(a[cx[up] - 1]);
putchar('\n');
//printf("%lld\n", a[cx[up] - 1]);
}
return 0;
}

UVALive 6198 A Terribly Grimm Problem的更多相关文章

  1. UVALive - 5107 - A hard Aoshu Problem

    题目链接:https://vjudge.net/problem/UVALive-5107 题目大意:用ABCDE代表不同的数字,给出形如ABBDE___ABCCC = BDBDE的东西: 空格里面可以 ...

  2. UVaLive 7359 Sum Kind Of Problem (数学,水题)

    题意:给定一个n,求前 n 个正整数,正奇数,正偶数之和. 析:没什么好说的,用前 n 项和公式即可. 代码如下: #pragma comment(linker, "/STACK:10240 ...

  3. A Boring Problem UVALive - 7676 (二项式定理+前缀和)

    题目链接: I - A Boring Problem UVALive - 7676 题目大意:就是求给定的式子. 学习的网址:https://blog.csdn.net/weixin_37517391 ...

  4. Gym 101194D / UVALive 7900 - Ice Cream Tower - [二分+贪心][2016 EC-Final Problem D]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

  5. UVALive 7457 Discrete Logarithm Problem (暴力枚举)

    Discrete Logarithm Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/D Description ...

  6. UVALive - 7041 The Problem to Slow Down You (回文树)

    https://vjudge.net/problem/UVALive-7041 题意 给出两个仅包含小写字符的字符串 A 和 B : 求:对于 A 中的每个回文子串,B 中和该子串相同的子串个数的总和 ...

  7. Gym 101194A / UVALive 7897 - Number Theory Problem - [找规律水题][2016 EC-Final Problem A]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

  8. Gym 101194C / UVALive 7899 - Mr. Panda and Strips - [set][2016 EC-Final Problem C]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

  9. Gym 101194E / UVALive 7901 - Ice Cream Tower - [数学+long double][2016 EC-Final Problem E]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

随机推荐

  1. aspx页面中获取当前浏览器url

    /假设当前浏览器地址为:http://www.360.net.cn/Group/Index.aspx?id=123 这其中如下介绍: ①."http://"是协议名 ②." ...

  2. @ManyToMany 两个表多对多关联

    两个表属于多对多关系 如 Teacher <=> Student 表teacher 主键 id 表student 主键id 中间关联表 teacher_student 两个字段 t_id ...

  3. 得于吾师傅的js知识 js类,单写模板,和私有保护的方法

    js的类的写法: 1,写法一:function内部包含this.function()如代码: var origin_class = function(name) { var lover = ''; t ...

  4. xfire找不到services.xml

    java.io.FileNotFoundException: class path resource [META-INF/xfire/services.xml] cannot be opened be ...

  5. win7+SQL2008无法打开物理文件 操作系统错误 5:拒绝访问 SQL Sever

    今天在win7+SQL2008的环境下操作分离附加数据库,分离出去然后再附加,没有问题.但是一把.mdf文件拷到其它文件夹下就出错,错误如下:无法打开物理文件 "E:\db\MyDB.mdf ...

  6. 嵌入式开发(一) Ubuntu12.04下搭建交叉编译环境

    操作系统:Ubuntu12.04 AMD64位 交叉编译环境:arm-Linux gcc版本4.4.3 前言: 首先理解一下交叉编译的意思.我们要给嵌入式设备写应用程序,但是又不能在嵌入式设备上完成所 ...

  7. (转)C++静态库与动态库

    本文出自 http://www.cnblogs.com/skynet/p/3372855.html 吴秦 什么是库 库是写好的现有的,成熟的,可以复用的代码.现实中每个程序都要依赖很多基础的底层库,不 ...

  8. wariging for you oh~

  9. ERROR:the server has either erred or is incapable of performing the requested operation

    openstack中,有时会经常出现这种错误,原因无二,一是安全组没有设置正确,二是openstack中网络配置会有些问题或者是相关的服务没有启动. 解决方法:1.安全组问题在nova.conf和ne ...

  10. 21 Merge Two Sorted Lists(两链表归并排序Easy)

    题目意思:对两个递增链表进行归并排序 思路:没什么好说的,二路归并 /** * Definition for singly-linked list. * struct ListNode { * int ...