Dividing the numbers CodeForces - 899C (构造)
大意: 求将[1,n]划分成两个集合, 且两集合的和的差尽量小.
和/2为偶数最小差一定为0, 和/2为奇数一定为1.
显然可以通过某个前缀和删去一个数得到.
#include <iostream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head#ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endifint n, m, a[N];
char s[N];int main() {scanf("%d", &n);int s = (1+n)*n/2, t = 0;REP(i,1,n) {t += i;if (t>=s/2&&t-s/2<=i) {vector<int> g;int r = 0;REP(j,1,i) if (j!=t-s/2) g.pb(j),r+=j; int rr = s-r;printf("%d\n%d ", abs(r-rr),int(g.size()));for (auto &&t:g) printf("%d ",t);return hr,0;}}
}
转载于:https://www.cnblogs.com/uid001/p/10763714.html
Dividing the numbers CodeForces - 899C (构造)相关推荐
- Educational Codeforces Round 96 (Rated for Div. 2) C. Numbers on Whiteboard(构造)
C. Numbers on Whiteboard 题意: 给你一个排列1-n,每次可以选择两个数,( ⌈ a + b 2 ⌉ \lceil \frac{a+b}{2} \rceil ⌈2a+b⌉)进 ...
- 【Codeforces Round #452 (Div. 2) C】 Dividing the numbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] n为偶数. l = 1, r = n (l,r)放在一组 l++,r-- 新的l,r放在另外一组 直到l+1==r 这个时候,判断两 ...
- D - Undoubtedly Lucky Numbers CodeForces - 244B(数论 )
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose deci ...
- Codeforces 1188A 构造
题意:给你一颗树,树的边权都是偶数,并且边权各不相同.你可以选择树的两个叶子结点,并且把两个叶子结点之间的路径加上一个值(可以为负数),问是否可以通过这种操作构造出这颗树?如果可以,输出构造方案.初始 ...
- Mashmokh and Numbers CodeForces - 415C
题意:就是n个数和k,每次按顺序那两个数,最大公约数的和为k. 思路:注意:当n=1,k>0时一定不存在,还有n=1,k=0时为1即可. 然后再正常情况下,第一组的最大公约数为k-n/2+1即可 ...
- B - Average Numbers CodeForces - 134A(水题,思维)
You are given a sequence of positive integers a1, a2, -, an. Find all such indices i, that the i-th ...
- Earth Wind and Fire CodeForces - 1148E (构造)
大意: $n$个石子, 第$i$个石子初始位置$s_i$, 每次操作选两个石子$i,j$, 要求$s_i<s_j$, 任取$d$, 满足$0\le 2d\le s_j-s_i$, 将$s_i,s ...
- Codeforces 题目合集+分类+代码 【Updating...】【361 in total】
961A - Tetris 模拟 ...
- Codeforces 313
A. Ilya and Bank Account 水题 B. Ilya and Queries 水,维护区间和 C. Ilya and Matrix 贪心.大的明显会被多次取. /*** Proble ...
最新文章
- PHP5.5.13 + Apache2.4.7安装配置流程详解
- java实现收货7天发通知,Java实训的第7天
- (转)解决Android SDK Manager无法更新或下载太慢问题
- 标图123123666
- read()/write()的生命旅程之四——第四章:writeback
- html坦克大战js代码包,js实现坦克大战游戏
- 4米乘以12米CAD图_这篇文章解决了我多年CAD制图比例问题!
- makefile的简单编写
- oracle支持utf8字符集,AL32UTF8/UTF8(Unicode)数据库字符集含义
- Two Shuffled Sequences
- 更新提示!Chrome新的零日漏洞正被利用
- 基于R语言或Matlab直接读取压缩包中的数据
- 数字图像处理实验(五)|图像复原{逆滤波和伪逆滤波、维纳滤波deconvwnr、大气湍流扰动模型、运动模糊处理fspecial}(附matlab实验代码和截图)
- 计算机网络之ip、子网掩码、网络号、主机号等概念解析
- 工业机器人什么情况下会出现奇点_机器人奇点是什么?他们怎么会像黑洞一样?...
- Louis Armstrong【路易斯·阿姆斯特朗】
- torch.flatten、np.flatten 详解
- Required string parameter ‘XXX‘ is not present
- 被网红时代毁掉的“小马云”
- Autoit 3 涉及中文内容程序失效的处理办法
热门文章
- Spring component detection logic
- Vue compile - Vue中的双大括号 {{ 是如何被解析(parse)的
- 在SAP Commerce里用SQL查询产品主数据
- SAP Netweaver ECATT介绍
- CRM Set Type com_commercial的UI界面
- 如何把Kubernetes config view里的base64编码过后的secret信息还原
- vsco使用教程_VSCO如何使用 vsco新手教程
- high severity error mysql_pg将运行日志导入表中的方法及时区问题解决
- java 全局变量 跳出递归循环_Java技术知识点的一些总结
- 个人博客管理系统_教程 | 一文搭建你的第一个免费专属博客