Codeforces 916C - Jamie and Interesting Graph
916C - Jamie and Interesting Graph
思路:构造。
对于1到n最短路且素数,那么1到n之间连2
对于最小生成树,找一个稍微大点的素数(比1e5大)构造一个和为这个素数的最小生成树
剩下的边都连1e9
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) /*const int N=1e5+5;
const int M=1e7+7;
vector<int>vc;
bool not_prime[M];
void prime(){
for(int i=2;i<M;i++){
if(!not_prime[i])vc.pb(i);
for(int j=0;i*vc[j]<M;j++){
not_prime[i*vc[j]]=true;
if(i%vc[j]==0)break;
}
}
cout<<vc[vc.size()-1]<<endl;//9999991
}*/
int main(){
ios::sync_with_stdio(false);
cin.tie();
//prime();
int n,m,t=;
cin>>n>>m;
if(n==)cout<<<<' '<<<<endl;
else cout<<<<' '<<t<<endl;
cout<<<<' '<<n<<' '<<<<endl;
t-=;
for(int i=;i<n;i++){
if(i!=n-)cout<<<<' '<<i<<' '<<<<endl,t-=;
else cout<<<<' '<<i<<' '<<t<<endl;
}
m-=n-;
for(int i=;i<=n;i++){
if(m==)break;
for(int j=i+;j<=n;j++){
if(m==)break;
cout<<i<<' '<<j<<' '<<<<endl;
m--;
if(m==)break;
}
if(m==)break;
}
return ;
}
Codeforces 916C - Jamie and Interesting Graph的更多相关文章
- CodeForces 916C Jamie and Interesting Graph  (构造)
		题意:给定两个数,表示一个图的点数和边数,让你构造出一个图满足 1- n 的最短路是素数,并且最小生成树也是素数. 析:首先 1 - n 的最短路,非常好解决,直接 1 连 n 就好了,但是素数尽量 ... 
- Jamie and Interesting Graph CodeForces - 916C
		http://codeforces.com/problemset/problem/916/C 好尬的题啊... #include<cstdio> #include<algorithm ... 
- 【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 1109D. Sasha and Interesting Fact from Graph Theory
		Codeforces 1109D. Sasha and Interesting Fact from Graph Theory 解题思路: 这题我根本不会做,是周指导带飞我. 首先对于当前已经有 \(m ... 
- 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 ... 
- Codeforces 703D Mishka and Interesting sum 离线+树状数组
		链接 Codeforces 703D Mishka and Interesting sum 题意 求区间内数字出现次数为偶数的数的异或和 思路 区间内直接异或的话得到的是出现次数为奇数的异或和,要得到 ... 
- Codeforces 1109D Sasha and Interesting Fact from Graph Theory (看题解) 组合数学
		Sasha and Interesting Fact from Graph Theory n 个 点形成 m 个有标号森林的方案数为 F(n, m) = m * n ^ {n - 1 - m} 然后就 ... 
- Codeforces 1109D. Sasha and Interesting Fact from Graph Theory  排列组合,Prufer编码
		原文链接https://www.cnblogs.com/zhouzhendong/p/CF1109D.html 题意 所有边权都是 [1,m] 中的整数的所有 n 个点的树中,点 a 到点 b 的距离 ... 
随机推荐
- 第七章之main函数和启动例程
			main函数和启动例程 为什么汇编程序的入口是_start,而C程序的入口是main函数呢?本节就来解释这个问题.在讲例 18.1 “最简单的汇编程序”时,我们的汇编和链接步骤是: $ as hell ... 
- linuxbash  父进程 子进程
			linux登陆linux,就获得一个bash,之后你的bash就是一个独立的进程,被称为pid的就是,之后你在bash下面执行的任何命令都是由这个bash所衍生的,那些被执行的命令被称为子进程.子进程 ... 
- 519. Random Flip Matrix(Fisher-Yates洗牌算法)
			1. 问题 给定一个全零矩阵的行和列,实现flip函数随机把一个0变成1并返回索引,实现rest函数将所有数归零. 2. 思路 拒绝采样 (1)先计算矩阵的元素个数(行乘以列),记作n,那么[0, n ... 
- Python tricks(6) -- python代码执行的效率
			python作为一个动态语言, 本身学习曲线比较平滑, 效率相比起来会比c++和java低一些. 脚本语言都是运行时编译的, 这个对于效率的影响是非常大的. 我借用参考1的代码, 加了点代码impor ... 
- java多线程----JUC集合”01之 框架
			java集合的架构.主体内容包括Collection集合和Map类:而Collection集合又可以划分为List(队列)和Set(集合). 1. List的实现类主要有: LinkedList, A ... 
- Window下安装npm
			Node.js停火各大技术论坛都在讨论,前段时间工作太忙没时间学习,趁着周末空闲玩玩,在网上找了些资料发现Node.js本身有windows版和unix版下载和使用都挺方便但是其扩展模块依赖复杂通过手 ... 
- HTTP从入门到入土(5)——HTTP报文格式
			HTTP报文格式 HTTP报文分为请求报文和响应报文,只有发送了请求报文,才会有响应报文. 常见的报文格式如下所示: 
- 20165211 学习基础和C语言调查
			20165211 学习基础和C语言调查 理论脱离实践是最大的不幸.--达芬奇 达芬奇,是我眼里最有嫌疑的穿越者. 绘画.天文.雕塑.音乐.发明.建筑,数学.生理.物理.天文.地质--我很难想象有一个人 ... 
- tf.random_uniform的使用
			tf.random_uniform((4, 4), minval=low,maxval=high,dtype=tf.float32)))返回4*4的矩阵,产生于low和high之间,产生的值是均匀分布 ... 
- C++中两个类中互相包含对方对象的指针问题(转载)
			出处:http://www.cnblogs.com/hanxi/archive/2012/07/25/2608068.html // A.h #include "B.h" clas ... 
