AtCoder Grand Contest 032-B - Balanced Neighbors (构造)
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
3
Sample Output 1 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 (构造)的更多相关文章
- AtCoder Grand Contest 032 B - Balanced Neighbors——构造
题意 B - Balanced Neighbors 给定一个整数 $N$($3\leq N \leq 100$),构造一个顶点编号为 $1...N$ 的无向图,需满足如下两个条件: 简单图且连通 存在 ...
- Atcoder Grand Contest 032
打的第一场Atcoder,已经知道会被虐得很惨,但没有想到竟然只做出一题-- 思维急需提升. A - Limited Insertion 这题还是很签到的. 感觉正着做不好做,我们反着来,把加数变为删 ...
- 【AtCoder Grand Contest 012C】Tautonym Puzzle [构造]
Tautonym Puzzle Time Limit: 50 Sec Memory Limit: 256 MB Description 定义一个序列贡献为1,当且仅当这个序列 由两个相同的串拼接而成 ...
- Atcoder Grand Contest 032 E - Modulo Pairing(乱搞+二分)
Atcoder 题面传送门 & 洛谷题面传送门 神仙调整+乱搞题. 首先某些人(including me)一看到最大值最小就二分答案,事实上二分答案对这题正解没有任何启发. 首先将 \(a_i ...
- AtCoder Grand Contest 032 A - Limited Insertion( 思维)
Time Limit: 2 sec / Memory Limit: 1024 MB Score : 400400 points Problem Statement Snuke has an empty ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- AtCoder Grand Contest 008
AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...
- AtCoder Grand Contest 007
AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...
随机推荐
- 小白学习Python之路---开发环境的搭建
本节内容 1.Python的介绍 2.发展史 3.安装Python 4.搭建开发环境 5.Hello World程序 一.Python的介绍 Python的创始人为荷兰人吉多·范罗苏姆(Guido v ...
- 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之十一 || AOP自定义筛选,Redis入门 11.1
代码已上传Github+Gitee,文末有地址 书说上文<从壹开始前后端分离[ .NET Core2.0 Api + Vue 2.0 + AOP + 分布式]框架之十 || AOP面向切面编程浅 ...
- 【反编译系列】四、反编译so文件(IDA_Pro)
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 安卓应用程序的开发语言是java,但是由于java层的代码很容易被反编译,而反编译c/c++程序的难度比较大,所以现在很多安卓应用程 ...
- WelcomeActivity【欢迎界面】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 简单记录下欢迎界面的布局以及倒计时和跳过功能. 效果图 代码分析 1.修改APP整个主题为无标题栏样式:styles.xml文件 & ...
- Redis~Linux环境下的部署
回到目录 Redis的生产环境建议部署到linux上,而在开发时可以连接windows版本,下面介绍如何在linux上部署redis. $ wget http://download.redis.io/ ...
- Python:logging.NullHandler 的使用
在使用 peewee 框架时,默认是不会出现日志消息的. from peewee import Model, CharField, DateTimeField, IntegerField from p ...
- Golang 语言的单元测试和性能测试(也叫 压力测试)
Golang单元测试对文件名和方法名,参数都有很严格的要求. 例如: 1.文件名必须以xx_test.go命名 2.方法必须是Test[^a-z]开头(T必须大写),func TestXxx (t * ...
- Docker最全教程之Ubuntu下安装Docker(十四)
前言 Ubuntu是一个以桌面应用为主的开源GNU/Linux操作系统,应用很广.本篇主要讲述Ubuntu下使用SSH远程登录并安装Docker,并且提供了Docker安装的两种方式,希望对大家有所帮 ...
- 前端javascript如何阻止按下退格键页面回退 但 不阻止文本框使用退格键删除文本
这段代码可以: document.onkeydown = function (e) { e.stopPropagation(); // 阻止事件冒泡传递 e.preventDefault(); // ...
- [转]Blue Prism VBO Cheat Sheet
本文转自:https://www.cheatography.com/ethanium/cheat-sheets/blue-prism-vbo/ Blue Prism MAPIEx Configure ...