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 [ 增量构造,树上 ...
随机推荐
- HDU 5188 背包
有N道题.要求得到最少W分 给出N道题的:每道题用时T.分数V,应在且必须在L时刻提交才干得分 问得到W分所用的最少的时间 以L-T排序,然后做01背包就可以 #include "stdio ...
- HDOJ--1869--六度分离(用三种算法写的,希望能比較出来他们之间的差别)
六度分离 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- TiDB 整体架构 结合yarn zookeeper分析架构
TiDB 简介与整体架构| PingCAP https://www.pingcap.com/docs-cn/overview/ 真正金融级高可用 相比于传统主从 (M-S) 复制方案,基于 Raft ...
- 两篇C++和VC++字符串的文章
有空挨个摘录写点心得 http://www.cnblogs.com/maowang1991/p/3572304.html http://www.cnblogs.com/maowang1991/p/35 ...
- Erlang-VM节点启动名冲突问题
今天在启动聊天的ErlangVM后,在日志中发现错误信息: Protocol 'inet_tcp': the name chatserver@127.0.0.1 seems to be in use ...
- NSString -- UILabel中字体有多种颜色,字符串自动计算高度/换行
一:UILabel中字体有多种颜色 UILabel *label = [[UILabel alloc] init]; label.frame = CGRectMake(, , , ); label.b ...
- codeforces round 421 div2 补题 CF 820 A-E
A Mister B and Book Reading O(n)暴力即可 #include<bits/stdc++.h> using namespace std; typedef lon ...
- Android应用开发完全退出程序的通用方法
在开发一个android应用时,有可能有N个Activity,而在每个Activity里的菜单里有个"退出程序"菜单,这里就要完全退出程序了,所以今天给大家分享的是Android应 ...
- 廖雪峰python3练习题三
条件判断 题目: 答案: #!/usr/bin/env python3 #-*- coding:utf-8 -*- heigth = 1.75 weigth = 80.5 bim = weigth / ...
- 【旧文章搬运】炉子给的SYSTEM_HANDLE_TYPE有点错误
原文发表于百度空间,2008-12-03========================================================================== 今天写程序 ...