题目大意是

给出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. 【转】数据库分页Java实现

    [转]数据库分页Java实现 MySQL分页 主要是MySQL数据库内置LIMIT函数 注意添加mysql的JAR包mysql-connector-java-5.1.13-bin.jar 在中小数据量 ...

  2. configSections(配置文件)

    转载:http://www.cnblogs.com/jhxk/articles/1609182.html 由于最近一个项目的数据库变动比较频繁, 为了减少数据层的负担, 打算采用.net的MVC框架, ...

  3. Android开发手记(16) 数据存储一 SharedPreferences

    Android为数据存储提供了五种方式: 1.SharedPreferences 2.文件存储 3.SQLite数据库 4.ContentProvider 5.网络存储 SharedPreferenc ...

  4. ViewPager 嵌套Listview 让Listview响应 ViewPager 左右滑事件

    一段拦截判断而已.   之前一直误解了一个拦截的描述.导致搞了半天. 结论: onInterceptTouchEvent 返回true,就由本身View的onTouchEvent进行事件消费. /** ...

  5. c-指针的指针

    概述: 贴上一个'经典C语言程序设计100例'的第77个程序 #include <stdio.h> int main(void) { char *s[]={"man", ...

  6. 【转】block一点也不神秘————如何利用block进行回调

    我们在开发中常常会用到函数回调,你可以用通知来替代回调,但是大多数时候回调是比通知方便的,所以何乐而不为呢?如果你不知道回调使用的场景,我们来假设一下: 1.我现在玩手机 2.突然手机没有电了 3.我 ...

  7. 【转】 分析iOS Crash文件:符号化iOS Crash文件的3种方法

    当你的应用提交到AppStore或者各个渠道之后,请问你多久会拿到crash文件?你如何分析crash文件的呢? 上传crash文件 你的应用应当有模块能够在应用程序crash的时候上传crash信息 ...

  8. jQuery中自定义简单动画的实现

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  9. 15 3Sum(寻找三个数之和为指定数的集合Medium)

    题目意思:给一个乱序数组,在里面寻找三个数之和为0的所有情况,这些情况不能重复,增序排列 思路:前面2sum,我用的是map,自然那道题map比双指针效率高,这道题需要先排序,再给三个指针,i.j.k ...

  10. grails-MappingException: Could not determine Type

    在用grails的时候遇到这个问题,反复调试了很久,没有进展,同时敲了几个命令后好了,真纠结,这是框架的问题吗? 问题: Caused by MappingException: Could not d ...