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:

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
3

Sample Output 1 Copy

Copy
2
1 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的边

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
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;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/ int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
gbtb;
int n;
cin>>n;
std::vector<pii> v;
int ans=;
repd(i,,n)
{
repd(j,i+,n)
{
if(n&)
{
if(i+j!=n)
{
ans++;
v.push_back(mp(i,j));
// cout<<i<<" "<<j<<endl;
}
}else
{
if(i+j!=n+)
{
ans++;
v.push_back(mp(i,j));
// cout<<i<<" "<<j<<endl;
}
}
}
}
cout<<ans<<endl;
for(auto x: v)
{
cout<<x.fi<<" "<<x.se<<endl;
} return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}

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. Java读取excel表,getPhysicalNumberOfCells()和getLastCellNum区别

    excel表存入数据库,发现有时报数组下标越界异常.调试发现用了 getPhysicalNumberOfCells(),这个是用来获取不为空的的列个数. getLastCellNum是获取最后一个不为 ...

  2. 死磕 java集合之CopyOnWriteArraySet源码分析——内含巧妙设计

    问题 (1)CopyOnWriteArraySet是用Map实现的吗? (2)CopyOnWriteArraySet是有序的吗? (3)CopyOnWriteArraySet是并发安全的吗? (4)C ...

  3. 强化学习(十)Double DQN (DDQN)

    在强化学习(九)Deep Q-Learning进阶之Nature DQN中,我们讨论了Nature DQN的算法流程,它通过使用两个相同的神经网络,以解决数据样本和网络训练之前的相关性.但是还是有其他 ...

  4. ubuntu16.04下编译安装vim8.1

    之前写过一篇centos7下编译安装vim8.0的教程,ubuntu16.04相比centos7下安装过程不同在于依赖包名字的不同,其余都是一样.下面给出ubuntu16.04编译安装vim8.0需要 ...

  5. java内存溢出的情况解决方法

    内存溢出虽然很棘手,但也有相应的解决办法,可以按照从易到难,一步步的解决. 第一步,就是修改JVM启动参数,直接增加内存.这一点看上去似乎很简单,但很容易被忽略.JVM默认可以使用的内存为64M,To ...

  6. 【面试】Spring事务面试考点吐血整理(建议珍藏)

    Spring和事务的关系 关系型数据库.某些消息队列等产品或中间件称为事务性资源,因为它们本身支持事务,也能够处理事务. Spring很显然不是事务性资源,但是它可以管理事务性资源,所以Spring和 ...

  7. SLAM+语音机器人DIY系列:(一)Linux基础——3.Linux命令行基础操作

    摘要 由于机器人SLAM.自动导航.语音交互这一系列算法都在机器人操作系统ROS中有很好的支持,所以后续的章节中都会使用ROS来组织构建代码:而ROS又是安装在Linux发行版ubuntu系统之上的, ...

  8. SpringBoot系列——Redis

    前言 Redis是一个缓存.消息代理和功能丰富的键值存储.StringBoot提供了基本的自动配置.本文记录一下springboot与redis的简单整合实例 官方文档:https://docs.sp ...

  9. .net 配置swagger

    第一步: 在nuget.org中查找Swashbuckle并下载 在nuget.org中查找Swagger.net.UI,并下载 第二步: 下载完之后,App_Start多了三个文件 Swagger. ...

  10. 创建索引CreateIndex

    nuget引用NEST new一个客户端 源码可查ElasticClient.cs new一个ElasticClient有多种方式 第一种 ES地址是http://localhost:9200,可以直 ...