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 的距离 ...
随机推荐
- Lintcode: k Sum II
Given n unique integers, number k (1<=k<=n) and target. Find all possible k integers where the ...
- HDU 5059 Help him(简单模拟题)
http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目大意: 给定一个字符串,如果这个字符串是一个整数,并且这个整数在[a,b]的范围之内(包括a,b),那 ...
- 【页面加速】配置Nginx加载ngx_pagespeed模块,加快网站打开的速度
ngx_pagespeed 是一个 Nginx 的扩展模块,可以加速你的网站,减少页面加载时间,它会自动将一些提升web性能的实践应用到网页和相关的资源(CSS.JS和图片)上,无需你修改内容和流程. ...
- BootStrap同时显示多个Modal解决方案
使用BootStrap自带的Modal的时候,如果同时调用多个Modal,那么只能看到背景颜色加深但是看不见新的Modal页面. 问题主要是Modal的z-index有问题,重新计算z-index并赋 ...
- SpringMVC+Spring+Mybatis+Maven+mysql整合
一.准备工作1.工具:jdk1.7.0_80(64)+tomcat7.0.68+myeclipse10.6+mysql-5.5.48-win322. 开发环境安装配置.Maven项目创建(参考:htt ...
- Java Callable接口——有返回值的线程
实际开发过程中,我们常常需要等待一批线程都返回结果后,才能继续执行.<线程等待——CountDownLatch使用>中我们介绍了CountDownLatch的使用,通过使用CountDow ...
- linux常用命令:chkconfig 命令
chkconfig命令用来安装,查看或修改 services随系统启动的启动选项的设置.是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各 ...
- nginx服务器的rewrite功能
nginx编译的时候默认是把rewrite功能编辑进去的,但是因为rewrite需要使用正则表达式,因此需要安装pcre依赖包. yum install -y pcre pcre-install re ...
- Python3 ChromeDriver与Chrome版本映射表(更新至v2.43)
Python3 ChromeDriver与Chrome版本映射表(更新至v2.43) ChromeDriver下载链接:http://chromedriver.storage.googleapis.c ...
- Linux服务器上Tomcat的Web工程部署
Linux服务器上Tomcat的Web工程部署 部署Web应用到Tomcat服务器就是将开放好的JavaWeb应用打包成war包,然后发布到tomcat服务器的webapps目录下: 步骤1,先进入t ...