Codeforces Round #452 (Div. 2)
来源:互联网 发布:四维星窗帘设计软件 编辑:程序博客网 时间:2024/06/05 16:14
题意:
把1到n这些数,分成两堆,让他们的差值最小,且任意输出一组。
POINT:
首先可以想到背包做,但是感觉会tle。
因为数字是连续的:
所以n%4==0时,肯定可以平分, 比如1 2 3 4 ,那么(1,4)(2,3)。比如4 5 6 7 ,那么(4,7)(5,6)
所以讨论余1,2,3时。
余1,就先挑出1,然后让2-n平分,最后任意给一个1.差值就是1
余2,就先挑出1,2,然后让3-n平分,最后每边给一个1或2,差值是1.
余3,一边给3,一边给1 2,差值为0
#include <iostream>#include <string>#include <string.h>#include <math.h>#include <vector>#include <map>#include <stdio.h>#include <algorithm>using namespace std;int n;int main(){cin>>n;if(n%4==0){printf("0\n");printf("%d",n/2);int len=n/4;for(int i=0;i<len;i++){printf(" %d %d",1+i,n-i);}}else if(n%4==1){printf("1\n");printf("%d",n/2);int len=n/4;for(int i=0;i<len;i++){printf(" %d %d",2+i,n-i);}}else if(n%4==2){printf("1\n");printf("%d",n/2);int len=n/4;printf(" 1");for(int i=0;i<len;i++){printf(" %d %d",3+i,n-i);}}else if(n%4==3){printf("0\n");printf("%d",n/2);int len=n/4;printf(" 3");for(int i=0;i<len;i++){printf(" %d %d",4+i,n-i);}}}
阅读全文
0 0
- Codeforces Round #452 (Div. 2)
- Codeforces Round #452 (Div. 2)
- Codeforces Round #452 (Div. 2)
- Codeforces Round #452 (Div. 2)
- Codeforces Round #452 (Div. 2)
- Codeforces Round #452 (Div. 2)
- Codeforces Round #452 (Div. 2) A-C
- Codeforces Round #452 (Div. 2) C
- Codeforces Round #452 (Div. 2)划水报告
- Codeforces Round #452 (Div. 2) D
- Codeforces Round #452 (Div. 2) A
- Codeforces Round #452 (Div. 2) B
- Codeforces Round #452 (Div. 2) C
- Codeforces Round #452 (Div. 2) D
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- h5学习笔记:http-server小工具
- linux --> shell --> bash001
- 安卓第三方登录之微信登录(图文详解)
- python中两种实现排序的方法:冒泡排序和插入排序
- finally块的执行
- Codeforces Round #452 (Div. 2)
- spring-framework框架知识点罗列
- 用for循环和while循环写华氏温度与摄氏温度的转化
- Python学习笔记(一)基础
- 关于typedef的用法总结
- mongodb对数组中的所有元素进行一次性修改方法(限3.6版本)
- 线段覆盖系列
- linux内核kallsyms机制分析
- 数据结构与算法复习第一弹(快速排序)