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;
#endif int 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;
}
}
}
Dividing the numbers CodeForces - 899C (构造)的更多相关文章
- Codeforces Round #452 (Div. 2) C. Dividing the numbers(水)
C. Dividing the numbers Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in t ...
- Magic Numbers CodeForces - 628D
Magic Numbers CodeForces - 628D dp函数中:pos表示当前处理到从前向后的第i位(从1开始编号),remain表示处理到当前位为止共产生了除以m的余数remain. 不 ...
- UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂)
UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂) 题目链接 题目大意:假设有一个合数.然后它满足随意大于1小于n的整数a, 满足a^n%n = a;这种合数叫做Ca ...
- Codeforces 899C - Dividing the numbers
传送门:http://codeforces.com/contest/899/problem/C 本题是一个数学问题——集合划分. 将集合{1,2,...,n}划分成两个集合,使得两个集合的元素之和的绝 ...
- Codeforces Round #452 (Div. 2)-899A.Splitting in Teams 899B.Months and Years 899C.Dividing the numbers(规律题)
A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input standar ...
- codeforces 509 D. Restoring Numbers(数学+构造)
题目链接:http://codeforces.com/problemset/problem/509/D 题意:题目给出公式w[i][j]= (a[i] + b[j])% k; 给出w,要求是否存在这样 ...
- 【Codeforces Round #452 (Div. 2) C】 Dividing the numbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] n为偶数. l = 1, r = n (l,r)放在一组 l++,r-- 新的l,r放在另外一组 直到l+1==r 这个时候,判断两 ...
- #452 Div2 Problem C Dividing the numbers ( 思维 || 构造 )
题意 : 将从 1 ~ n 的数分成两组,要求两组和的差值尽可能小,并输出其中一组的具体选数情况 分析 : 如果将这 n 个数从大到小四个一组来进行选择的话那么差值就为 0 ,然后再来考虑 n%4 ! ...
- Codeforces 746G(构造)
G. ...
随机推荐
- 2018-2019-2 20175205实验一《Java开发环境的熟悉》实验报告
2018-2019-20175205实验一<Java开发环境的熟悉>实验报告 实验步骤 (一)命令行下Java程序开发 在Linux下运行结果: 在IDEA中运行结果: (二)IDEA下J ...
- GO语言的包
包介绍 包(package)是多个Go源码的集合,go语言有很多内置包,比如fmt,os,io等. 定义包 main包是一个可执行的包,只应用程序的入口包,编译完会生成一个可执行文件. 包名可以不和文 ...
- Python数据分析Pandas库之熊猫(10分钟二)
pandas 10分钟教程(二) 重点发法 分组 groupby('列名') groupby(['列名1','列名2',.........]) 分组的步骤 (Splitting) 按照一些规则将数据分 ...
- asp.net处理机制管道事件
自定义的托管模块HTTP模块可以向System.Web.HttpApplication对象注册下面一系列事件: AcquireRequestState 当ASP.NET运行时准备好接收当前HTTP请求 ...
- sublime 使用链接
链接 :http://www.cnblogs.com/gaosheng-221/p/6108033.html https://www.zhihu.com/question/24896283 http ...
- 论使用HashMap优化双层For循环的实际性能
当需要对两个集合进行相互操作的时候,一般需要进行双层For循环,但我们知道双层For在数量越大的时候性能影响越大 这时候我们会想到的其中一种解决方法就是利用Hashmap在查找数据的高效上来优化双层F ...
- svg---基础1
svg:可缩放矢量图形是基于可扩展标记语言(标准通用标记语言的子集),用于描述二维矢量图形的一种图形格式.它由万维网制定,是一个开放标准. 官网:http://www.w3.org/2000/svg ...
- JavaWeb三大组件
一.JavaWeb三大组件 Servlet,Listener,Filter.它们在JavaWeb开发中分别提供不同的功能. JavaWeb三大组件都必须在Web.xml中配置 二.三大组件 1.Ser ...
- ASP.NET - Validators
ASP.NET validation controls validate the user input data to ensure that useless, unauthenticated, or ...
- javascript prop和attr的区别
在网上找了一些资料,通过自己去寻找,尝试,此次做一次总结. 1/ attr()是jQuery 1.0版本就有的函数, prop()是jQuery 1.6版本新增的函数.毫无疑问,在1.6之前, ...