题目链接:https://atcoder.jp/contests/abc131/tasks/abc131_e

题目大意

  给定 N 和 K,要求构造有 N 个点,恰有 K 对点,它们的最短距离为 2 的图。

分析

  用笔画画就能发现,把 1 号点放中间,其余点连 1 号点就能产生最多对最短距离为 2 的点对。
  然后除 1 号点之外的点每连一条线,数目就减少 1。

代码如下

 #include <bits/stdc++.h>
using namespace std; #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define UNIQUE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define REMOVE(x, c) x.erase(remove(x.begin(), x.end(), c), x.end()); // 删去 x 中所有 c
#define TOLOWER(x) transform(x.begin(), x.end(), x.begin(),::tolower);
#define TOUPPER(x) transform(x.begin(), x.end(), x.begin(),::toupper); #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} inline int gc(){
static const int BUF = 1e7;
static char buf[BUF], *bg = buf + BUF, *ed = bg; if(bg == ed) fread(bg = buf, , BUF, stdin);
return *bg++;
} inline int ri(){
int x = , f = , c = gc();
for(; c<||c>; f = c=='-'?-:f, c=gc());
for(; c>&&c<; x = x* + c - , c=gc());
return x*f;
} template<class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
} inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
} //min <= aim <= max
template<typename T>
inline bool BETWEEN(const T aim, const T min, const T max) {
return min <= aim && aim <= max;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef pair< int, PII > PIPII;
typedef pair< string, int > PSI;
typedef pair< int, PSI > PIPSI;
typedef set< int > SI;
typedef set< PII > SPII;
typedef vector< int > VI;
typedef vector< double > VD;
typedef vector< VI > VVI;
typedef vector< SI > VSI;
typedef vector< PII > VPII;
typedef map< int, int > MII;
typedef map< int, string > MIS;
typedef map< int, PII > MIPII;
typedef map< PII, int > MPIII;
typedef map< string, int > MSI;
typedef map< string, string > MSS;
typedef map< PII, string > MPIIS;
typedef map< PII, PII > MPIIPII;
typedef multimap< int, int > MMII;
typedef multimap< string, int > MMSI;
//typedef unordered_map< int, int > uMII;
typedef pair< LL, LL > PLL;
typedef vector< LL > VL;
typedef vector< VL > VVL;
typedef priority_queue< int > PQIMax;
typedef priority_queue< int, VI, greater< int > > PQIMin;
const double EPS = 1e-;
const LL inf = 0x7fffffff;
const LL infLL = 0x7fffffffffffffffLL;
const LL mod = 1e9 + ;
const int maxN = 2e5 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; int N, K, M; int main(){
//freopen("MyOutput.txt","w",stdout);
//freopen("input.txt","r",stdin);
//INIT();
cin >> N >> K;
M = N * (N - ) / - K;
if(M < N - ) M = -; cout << M << endl;
if(M != -) {
int cnt = N - ;
while(M > ) {
For(i, N - cnt + , min(N, N - cnt + M)) cout << N - cnt << " " << i << endl;
M -= cnt--;
}
}
return ;
}

最新文章

  1. 带你一步步的了解“C#事件”机制
  2. PCI Express(六) - Simple transactions
  3. mybatis Generator配置文件详解
  4. 51nod 1134 最长递增子序列
  5. 在桌面chrome中调试android设备中的web页面
  6. MVC字符串处理及MVC @RenderSection小计
  7. LA 5061 LCA tarjan 算法
  8. CodeForces 558A
  9. NET下RabbitMQ实践[配置篇]
  10. imgur.py
  11. Team Foundation Server 2015使用教程--默认团队成员添加
  12. C#验证IP地址
  13. EventBus实现 - 发布订阅 - XML加载
  14. js 、jq强化复习
  15. windows手动去重 通配符
  16. BZOJ1022[SHOI2008]小约翰的游戏——anti-SG(反尼姆博弈)
  17. Please add or free up more resources then turn off safe mode manually.
  18. TVS二极管和稳压二极管的区别
  19. 每日英语:China&#39;s Bigger Innovation Problem
  20. int类型转换byte类型

热门文章

  1. php中如何实现多进程
  2. JAVA求回文数
  3. git 强制取消本地修改
  4. keepalived高可用haproxy负载均衡varnish缓存wordpress的动静分离(第一次配置成功)
  5. C# WinfForm 控件之dev报表 XtraReport (五) 并排报表
  6. ArcGis拓扑——规则、概念与要点
  7. 软工-五月心得体会 PB16110698
  8. Mysql 查询视图出现The user specified as a definer (&#39;root&#39;@&#39;%&#39;) does not exist的问题
  9. Linux网络编程 了解
  10. 随笔记录 误删boot恢复 2019.8.7