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 ...
随机推荐
- PHP——isset和empty
前言 对于这两个PHP函数大家肯定都很熟悉,但是其二者的区别又有那些呢? 对比 isset | 检测变量是否被设置过 1. 变量不存在,返回FALSE 2. 变量存在且其值为NULL,返回FALSE ...
- 测试输出System.err与System.out
来源:http://www.cnblogs.com/guozp/p/6099902.html 1.System.out在JVM和操作系统都具有缓存功能,输出的东西不一定实时输出,可能积累几个字符才会一 ...
- DotNetCore跨平台~EFCore废弃了TransactionScope取而代之的Context.Database.BeginTransaction
回到目录 TransactionScope是.net平台基于的分布式事务组件,它默认为本地事务,同时当系统有需要时可以自动提升为分布式事务,而对系统的前提是要开启MSDTC服务,必要时需要在数据库服务 ...
- [翻译 EF Core in Action] 1.5 关于NoSql
Entity Framework Core in Action Entityframework Core in action是 Jon P smith 所著的关于Entityframework Cor ...
- SmartSql V3 重磅发布
超轻量级的ORM框架!107kb 更新内容 移除Dapper依赖 支持存储过程 增强扩展性 重构代码 优化缓存策略 动态实现仓储接口 支持 参数&结果映射 & TypeHandler ...
- SLAM+语音机器人DIY系列:(二)ROS入门——8.理解roslaunch在大型项目中的作用
摘要 ROS机器人操作系统在机器人应用领域很流行,依托代码开源和模块间协作等特性,给机器人开发者带来了很大的方便.我们的机器人“miiboo”中的大部分程序也采用ROS进行开发,所以本文就重点对ROS ...
- c# aes,des,md5加密等解密算法
一:可逆加密,即是能加密也能解密 对称可逆加密:加密后能解密回原文,加密key和解密key是一个 加密算法都是公开的,密钥是保密的, 即使拿到密文 你是推算不了密钥 也推算不了原文 加密解密的速度快, ...
- void类型和void* 的用法
C语言中的void 和 void * 总结 1.void的作用 c语言中,void为“不确定类型”,不可以用void来声明变量.如:void a = 10:如果出现这样语句编译器会报错:variab ...
- 斑马打印机的安装调试,生成PDF
1. 我使用的斑马打印机GK888T.有问题打客服,耐心等待.售后电话4006456456得到了解决. 2. 我遇到的问题是打印一张之后指示灯变为红灯,时好时坏.解决方案,长按指示键,待指示灯连续 ...
- 六大设计原则(四)ISP接口隔离原则(上)
ISP的定义 首先明确接口定义 实例接口 我们在Java中,一个类用New关键字来创建一个实例.抛开Java语言我们其实也可以称为接口.假设Person zhangsan = new Person() ...