Jamie and Interesting Graph CodeForces - 916C
http://codeforces.com/problemset/problem/916/C
好尬的题啊。。。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
struct E
{
int u,v,w;
}e[];
int ne;
int n,m;
bool nprime[];
int prime[],len;
int x=,y=;
int main()
{
int i,j,t;
nprime[]=;
for(i=;i<=;i++)
{
if(!nprime[i]) prime[++len]=i;
for(j=;j<=len&&i*prime[j]<=;j++)
{
nprime[i*prime[j]]=;
if(i%prime[j]==) break;
}
}
scanf("%d%d",&n,&m);m-=(n-);
for(i=;i<n;i++) e[++ne]=(E){i,i+,};
for(i=;i<=m;i++)
{
if(y==n) x++,y=x+;
else y++;
e[++ne]=(E){x,y,};
}
for(t=;nprime[t+n-];t++);
e[].w+=t;
printf("%d %d\n",t+n-,t+n-);
for(i=;i<=ne;i++) printf("%d %d %d\n",e[i].u,e[i].v,e[i].w);
return ;
}
Jamie and Interesting Graph CodeForces - 916C的更多相关文章
- Codeforces 916C - Jamie and Interesting Graph
916C - Jamie and Interesting Graph 思路:构造. 对于1到n最短路且素数,那么1到n之间连2 对于最小生成树,找一个稍微大点的素数(比1e5大)构造一个和为这个素数的 ...
- CodeForces 916C Jamie and Interesting Graph (构造)
题意:给定两个数,表示一个图的点数和边数,让你构造出一个图满足 1- n 的最短路是素数,并且最小生成树也是素数. 析:首先 1 - n 的最短路,非常好解决,直接 1 连 n 就好了,但是素数尽量 ...
- 【Codeforces Round #457 (Div. 2) C】Jamie and Interesting Graph
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找比n-1大的最小的素数x 1-2,2-3..(n-2)-(n-1)长度都为1 然后(n-1)-n长度为(x-(n-2)) 然后其他 ...
- CF916C Jamie and Interesting Graph
思路:构造 实现: #include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n ...
- Codeforces Beta Round #9 (Div. 2 Only) E. Interesting Graph and Apples 构造题
E. Interesting Graph and Apples 题目连接: http://www.codeforces.com/contest/9/problem/E Description Hexa ...
- Bubble Sort Graph CodeForces - 340D || 最长不下降/上升子序列
Bubble Sort Graph CodeForces - 340D 题意: 给出一个n个数的数列,建一个只有n个结点没有边的无向图,对数列进行冒泡排序,每交换一对位置在(i,j)的数在点i和点j间 ...
- Almost Acyclic Graph CodeForces - 915D (思维+拓扑排序判环)
Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megaby ...
- D - Beautiful Graph CodeForces - 1093D (二分图染色+方案数)
D - Beautiful Graph CodeForces - 1093D You are given an undirected unweighted graph consisting of nn ...
- CodeForces 840B - Leha and another game about graph | Codeforces Round #429(Div 1)
思路来自这里,重点大概是想到建树和无解情况,然后就变成树形DP了- - /* CodeForces 840B - Leha and another game about graph [ 增量构造,树上 ...
随机推荐
- ubuntu编译airplay
1.alsa/asoundlib.h: No such file or directory 缺少一个库: apt-get install libasound2-dev 2.fatal error: ...
- js操作文件 HTML5版
js操作文件 HTML5版,有需要的朋友可以参考下. <!DOCTYPE html> <html> <head> <title>JSFileReader ...
- 解压Zip
import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import ja ...
- 多媒体开发之---h264 取流解码分析
1. nalu_unit_type = *((unsigned char *)pEmptyBuf->bufVirtAddr+4); nalu_unit_type = nalu_unit_type ...
- VUE 之 生命周期
1. Vue实例的生命周期分为8个周期 1.1 beforeCreate:在实例创建前 <div id="app"> {{ name }} <button @cl ...
- 开启 J2EE(六)— Servlet之Filter具体解释及乱码处理实例
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/akkzhjj/article/details/36471477 定义和功能 Filter:过滤器,它 ...
- Ubuntu 配置 nfsserver
https://help.ubuntu.com/lts/serverguide/network-file-system.html#nfs-installation 网络文件系统 (NFS) NFS 允 ...
- XMLHttp.send()不传参时必须传null吗?
xmlhttp的send是传递参数用的,但是只有在使用post方式提交请求的时候才有用如下:xmlhttp.open("post",url,true); ...xmlhttp.se ...
- zoj 1109 Language of FatMouse 解题报告
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=109 题目意思:给出一个mouse-english词典,问对于输入的m ...
- Linux系统中的运行级别
什么是运行级呢?简单的说,运行级就是操作系统当前正在运行的功能级别. 它让一些程序在一个级别启动,而另外一个级别的时候不启动. Linux系统的有效登录模式有0~9共十种,不过沿用UNIX系统的至多6 ...