CodeForces - 1009D Relatively Prime Graph
直接暴力找点对就行了,可以证明gcd=1是比较密集的,所以复杂度略大于 O(N log N)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5; int gcd(int x,int y){ return y?gcd(y,x%y):x;} int n,m,u[N+5],v[N+5]; int main(){
scanf("%d%d",&n,&m);
if(n-1>m){ puts("Impossible"); return 0;}
for(int i=2;i<=n;i++) u[m]=i,v[m--]=i-1;
for(int i=3;i<=n&&m;i++)
for(int j=i-2;j&&m;j--) if(gcd(i,j)==1) u[m]=i,v[m--]=j;
if(m){ puts("Impossible"); return 0;}
puts("Possible");
for(int i=1;u[i];i++) printf("%d %d\n",u[i],v[i]);
return 0;
}
CodeForces - 1009D Relatively Prime Graph的更多相关文章
- codeforces 1009D Relatively Prime Graph【欧拉函数】
题目:戳这里 题意:要求构成有n个点,m条边的无向图,满足每条边上的两点互质. 解题思路: 显然1~n这n个点能构成边的条数,就是2~n欧拉函数之和(x的欧拉函数值代表小于x且与x互质的数的个数. 因 ...
- Codeforces 1009D:Relatively Prime Graph
D. Relatively Prime Graph time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces 459E Pashmak and Graph(dp+贪婪)
题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依 ...
- D. Relatively Prime Graph
Let's call an undirected graph G=(V,E)G=(V,E) relatively prime if and only if for each edge (v,u)∈E( ...
- Relatively Prime Graph CF1009D 暴力 思维
Relatively Prime Graph time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- ACM - 最短路 - CodeForces 295B Greg and Graph
CodeForces 295B Greg and Graph 题解 \(Floyd\) 算法是一种基于动态规划的算法,以此题为例介绍最短路算法中的 \(Floyd\) 算法. 我们考虑给定一个图,要找 ...
- 【Codeforces 1009D】Relatively Prime Graph
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 1000以内就有非常多组互质的数了(超过1e5) 所以,直接暴力就行...很快就找完了 (另外一开始头n-1条边找1和2,3...n就好 [代 ...
- Codeforces Global Round 4 Prime Graph CodeForces - 1178D (构造,结论)
Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wan ...
- [Codeforces 1178D]Prime Graph (思维+数学)
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...
随机推荐
- HDU 1148 Rock-Paper-Scissors Tournament (模拟)
题目链接 Problem Description Rock-Paper-Scissors is game for two players, A and B, who each choose, inde ...
- shell 监控磁盘使用率【转】
方案一: disks=(`df |sed 1d | awk '{print $1,$5}'|tr -d %`) len=${#disks[@]} ;i<=$len;i=i+));do ];the ...
- ahttp
# -*- coding: utf-8 -*- # @Time : 2018/8/20 14:35 # @Author : cxa # @File : chttp.py # @Software: Py ...
- Petrozavodsk Summer Training Camp 2017
Petrozavodsk Summer Training Camp 2017 Problem A. Connectivity 题目描述:有\(n\)个点,现不断地加边.每条边有一种颜色,如果一个点对\ ...
- HDU 6205 2017沈阳网络赛 思维题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6205 题意:给你n堆牌,原本每一堆的所有牌(a[i]张)默认向下,每次从第一堆开始,将固定个数的牌(b ...
- u-boot启动第二阶段以及界面命令分析
u-boot第一阶段完成了一些平台相关的硬件的配置,第一阶段所做的事情也是为第二阶段的准备,我们知道在第一阶段最后时搭建好C运行环境,之后调用了start_armboot(),那么很显然第二阶段从st ...
- python模块之xlrd,xlwt,读写execl(xls,xlsx)
安装xlrd,xlwt pip install xlrd xlwt xlrd读取execl [环境ipython python2.7.5] import xlrd book = xlrd.open_w ...
- 对cgic的理解——name选项
#include <stdio.h>#include <stdlib.h>#include <string.h>#include "cgic.h" ...
- Windows内核执行体对象管理器的操作过程与分析
我之前写过一个有关于对象管理的读书笔记.但是这篇文章与前面的不同,这是我个人对对象管理器到底是什么的一个分析,而且也是直接对WRK代码进行的阅读. 执行体对象即我们通常所言的内核对象,我们知道Wind ...
- fastdfs5.10 centos6.9 安装配置
下载相关软件 https://codeload.github.com/happyfish100/fastdfs/tar.gz/V5.10http://download.csdn.net/detail/ ...