Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 700700 points

Problem Statement

You are given an integer NN. Build an undirected graph with NN vertices with indices 11 to NN that satisfies the following two conditions:

  • The graph is simple and connected.
  • There exists an integer SS such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is SS.

It can be proved that at least one such graph exists under the constraints of this problem.

Constraints

  • All values in input are integers.
  • 3≤N≤1003≤N≤100

Input

Input is given from Standard Input in the following format:

  1. NN

Output

In the first line, print the number of edges, MM, in the graph you made. In the ii-th of the following MM lines, print two integers aiai and bibi, representing the endpoints of the ii-th edge.

The output will be judged correct if the graph satisfies the conditions.


Sample Input 1 Copy

Copy
  1. 3

Sample Output 1 Copy

Copy
  1. 2
  2. 1 3
  3. 2 3
  • For every vertex, the sum of the indices of the vertices adjacent to that vertex is 33.

题意:

给你一个数字n,

让你构造你简单图(无重边)

要求这个图的每一个节点所连接的节点的id值加起来相等。*(不用加自己的id值)

思路:

显然找规律的构造题。

我们反过来想,先构建一个完全图,设法去掉一些有规律的边,使整个图满足条件。

通过分析可以发现规律。

当n是奇数的时候,

删除i+j=n的边

否则

删除i+j=n+1的边

细节见代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <queue>
  7. #include <stack>
  8. #include <map>
  9. #include <set>
  10. #include <vector>
  11. #include <iomanip>
  12. #define ALL(x) (x).begin(), (x).end()
  13. #define rt return
  14. #define dll(x) scanf("%I64d",&x)
  15. #define xll(x) printf("%I64d\n",x)
  16. #define sz(a) int(a.size())
  17. #define all(a) a.begin(), a.end()
  18. #define rep(i,x,n) for(int i=x;i<n;i++)
  19. #define repd(i,x,n) for(int i=x;i<=n;i++)
  20. #define pii pair<int,int>
  21. #define pll pair<long long ,long long>
  22. #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
  23. #define MS0(X) memset((X), 0, sizeof((X)))
  24. #define MSC0(X) memset((X), '\0', sizeof((X)))
  25. #define pb push_back
  26. #define mp make_pair
  27. #define fi first
  28. #define se second
  29. #define eps 1e-6
  30. #define gg(x) getInt(&x)
  31. #define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
  32. using namespace std;
  33. typedef long long ll;
  34. ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  35. ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
  36. ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
  37. inline void getInt(int* p);
  38. const int maxn=;
  39. const int inf=0x3f3f3f3f;
  40. /*** TEMPLATE CODE * * STARTS HERE ***/
  41.  
  42. int main()
  43. {
  44. //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
  45. //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
  46. gbtb;
  47. int n;
  48. cin>>n;
  49. std::vector<pii> v;
  50. int ans=;
  51. repd(i,,n)
  52. {
  53. repd(j,i+,n)
  54. {
  55. if(n&)
  56. {
  57. if(i+j!=n)
  58. {
  59. ans++;
  60. v.push_back(mp(i,j));
  61. // cout<<i<<" "<<j<<endl;
  62. }
  63. }else
  64. {
  65. if(i+j!=n+)
  66. {
  67. ans++;
  68. v.push_back(mp(i,j));
  69. // cout<<i<<" "<<j<<endl;
  70. }
  71. }
  72. }
  73. }
  74. cout<<ans<<endl;
  75. for(auto x: v)
  76. {
  77. cout<<x.fi<<" "<<x.se<<endl;
  78. }
  79.  
  80. return ;
  81. }
  82.  
  83. inline void getInt(int* p) {
  84. char ch;
  85. do {
  86. ch = getchar();
  87. } while (ch == ' ' || ch == '\n');
  88. if (ch == '-') {
  89. *p = -(getchar() - '');
  90. while ((ch = getchar()) >= '' && ch <= '') {
  91. *p = *p * - ch + '';
  92. }
  93. }
  94. else {
  95. *p = ch - '';
  96. while ((ch = getchar()) >= '' && ch <= '') {
  97. *p = *p * + ch - '';
  98. }
  99. }
  100. }

AtCoder Grand Contest 032-B - Balanced Neighbors (构造)的更多相关文章

  1. AtCoder Grand Contest 032 B - Balanced Neighbors——构造

    题意 B - Balanced Neighbors 给定一个整数 $N$($3\leq N \leq 100$),构造一个顶点编号为 $1...N$ 的无向图,需满足如下两个条件: 简单图且连通 存在 ...

  2. Atcoder Grand Contest 032

    打的第一场Atcoder,已经知道会被虐得很惨,但没有想到竟然只做出一题-- 思维急需提升. A - Limited Insertion 这题还是很签到的. 感觉正着做不好做,我们反着来,把加数变为删 ...

  3. 【AtCoder Grand Contest 012C】Tautonym Puzzle [构造]

    Tautonym Puzzle Time Limit: 50 Sec  Memory Limit: 256 MB Description 定义一个序列贡献为1,当且仅当这个序列 由两个相同的串拼接而成 ...

  4. Atcoder Grand Contest 032 E - Modulo Pairing(乱搞+二分)

    Atcoder 题面传送门 & 洛谷题面传送门 神仙调整+乱搞题. 首先某些人(including me)一看到最大值最小就二分答案,事实上二分答案对这题正解没有任何启发. 首先将 \(a_i ...

  5. AtCoder Grand Contest 032 A - Limited Insertion( 思维)

    Time Limit: 2 sec / Memory Limit: 1024 MB Score : 400400 points Problem Statement Snuke has an empty ...

  6. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  7. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  8. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  9. AtCoder Grand Contest 008

    AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...

  10. AtCoder Grand Contest 007

    AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...

随机推荐

  1. 爬虫框架之Scrapy(一)

    scrapy简介 scrapy是一个用python实现为了爬取网站数据,提取结构性数据而编写的应用框架,功能非常的强大. scrapy常应用在包括数据挖掘,信息处理或者储存历史数据的一系列程序中. s ...

  2. IIS系统短文件名漏洞猜解过程

    今天看教程的时候,老师关于后台管理说到了短文件名漏洞,我就随便找了个网站猜解,可能是运气太好了,有了这次实践的过程,因为这个漏洞是13年的时候比较火,现在差不多都修复了,抓到一条漏网之鱼, 短文件名漏 ...

  3. 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之二 || 后端项目搭建

    前言 至于为什么要搭建.Net Core 平台,这个网上的解释以及铺天盖地,想了想,还是感觉重要的一点,跨平台,嗯!没错,而且比.Net 更容易搭建,速度也更快,所有的包均有Nuget提供,不再像以前 ...

  4. Vue.js-04:第四章 - 页面元素样式的设定

    一.前言 前端开发中有三大件:HTML.CSS.JavaScript,在前面的学习中,不管是学习 Vue 的指令系统还是 Vue 的事件修饰符,主要还是针对的是我们在前端开发中的 JavaScript ...

  5. 【Android Studio安装部署系列】二十一、Android studio将项目上传到github中

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 两个相关概念:git和github Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理.Git ...

  6. java~日期与字符串的转化

    在Java里我们可以通过SimpleDateFormat实现日期类型的格式化,即将它转为指定格式的字符串,当然像YearMonth这种特殊的类型,实现字符串转化最为容易,即直接toString()即可 ...

  7. LindDotNetCore~Scheduling任务调度模块的介绍

    回到目录 任务调度组件 位于Scheduling目录 基类JobBase,所有JOB都派生自它,重写Cron属性可以修改调度周期 支持单次JOB,即执行完成后马上停止 支持对外API接口,以便获取和修 ...

  8. unity中ScriptableObject在assetbundle中的加载

    转载请标明出处:http://www.cnblogs.com/zblade/ 以前都是写一些个人的调研博客,从今天开始,也写一些个人在开发中遇到的一些可以分享的趟坑博客,为后续的开发人员提供一些绵薄之 ...

  9. docker (2) 通用/镜像命令

    Docker 的常用命令: (1)Docker  help 命令: 可以查看有关docker的所有操作命令: (2)docker COMMAND -–help 查看docker 的某项命令的帮助文档 ...

  10. .net core +codefirst(.net core 基础入门,适合这方面的小白阅读,本文使用mysql或mssql)

    设置为model所在的那一层 前言 .net core mvc和 .net mvc开发很相似,比如 视图-模型-控制器结构.所以.net mvc开发员很容易入手.net core mvc .但是两个又 ...