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 [ 增量构造,树上 ...
随机推荐
- C++函数模板例子
//C++函数模板实例 #include <iostream>template <class Any>void Swap(Any &a, Any &b); in ...
- (org.openqa.selenium.WebDriverException: Unable to launch the app: Error: Trying to start logcat capture but it's already started! )错误解决办法
新增: capabilities.setCapability("autoLaunch",false); 将setup中的: driver = new AndroidDriver(n ...
- CSS 媒体类型 总结
CSS 媒体类型 媒体类型允许你指定文件将如何在不同媒体呈现.该文件可以以不同的方式显示在屏幕上,在纸张上,或听觉浏览器等等. 媒体类型 一些CSS属性只设计了某些媒体.例如"voice-f ...
- ReactMotion Demo8 分析
链接 首先通过spring函数Motion的style参数, 传入Motion Component, 计算style的过程: const style = lastPressed === i & ...
- 计算机学院大学生程序设计竞赛(2015’12)Pick Game
Pick Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 一步一步学Silverlight 2系列(15):数据与通信之ASMX
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- 如何在cowboy应用中指定mnesia数据库路径
创建mnesia数据库的步骤简述: 1)定义脚本: -module(mns). -export([setup/0, clean/0]). -record(user, { id, coin, diamo ...
- 使用cocoaPods加载框架的具体步骤:
注意事项: 1.使用之前备份一下代码.因为pod更新很快,如果某个文件名有中文,pod install 一下.整个项目可能就要废掉了. 2.如果不把pod文件推动到远程服务器. 每一次用的时候在本地p ...
- Android studio 构建太慢
/*********************************************************************************** * Android studi ...
- Name That Number
链接 分析:找出每一个字母对应的数字,然后看字典里面那个与其匹配 /* ID: **** PROG: namenum LANG: C++ */ #include<iostream> #in ...