codeforces 895A Pizza Separation 枚举
codeforces 895A Pizza Separation
题目大意:
- 分成两大部分,使得这两部分的差值最小(注意是圆形,首尾相连)
思路:
- 分割出来的部分是连续的,开二倍枚举。
- 注意不要看成01背包,一定多读题
代码:
#include <bits/stdc++.h>
using namespace std;
int a[800];
int main() {
int n,minval,sum,tot;
cin>>n;
tot=0;
for(int i=1;i<=n;++i) {
scanf("%d",&a[i]);
tot+=a[i];
}
for(int i=1;i<=n;++i) {
a[i+n]=a[i];
}
minval=tot;
for(int i=1;i<=n;++i) {
sum=0;
for(int j=i;j<=2*n;++j) {
if(j-i==n) break;
sum+=a[j];
minval=min(abs(tot-2*sum),minval);
}
}
cout<<minval<<endl;
return 0;
}
codeforces 895A Pizza Separation 枚举的更多相关文章
- 895A. Pizza Separation#分披萨问题(前缀和)
题目出处:http://codeforces.com/problemset/problem/895/A 题目大意:对于给出的一些角度的披萨分成两份,取最小角度差 #include<stdio.h ...
- Codeforces Round #448 (Div. 2) A. Pizza Separation【前缀和/枚举/将圆(披萨)分为连续的两块使其差最小】
A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeForces:#448 div2 a Pizza Separation
传送门:http://codeforces.com/contest/895/problem/A A. Pizza Separation time limit per test1 second memo ...
- Codeforces 895.A Pizza Separation
A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard ...
- #448 div2 a Pizza Separation
A. Pizza Separation time limit per test1 second memory limit per test256 megabytes inputstandard inp ...
- Educational Codeforces Round 61 C 枚举 + 差分前缀和
https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多 ...
- Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...
- CodeForces 617C【序枚举】
题意: 有两个点喷水,有很多个点有花,给出坐标. 求使得每个花都可以被喷到,两个喷水的半径的平方的和最小是多少. 思路: 枚举其中一个喷水的最大半径. 坑: 这题我贪心的思路有很大问题.一开始也是想这 ...
- codeforces 613B B. Skills(枚举+二分+贪心)
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
随机推荐
- 数据分析与展示——NumPy库入门
这是我学习北京理工大学嵩天老师的<Python数据分析与展示>课程的笔记.嵩老师的课程重点突出.层次分明,在这里特别感谢嵩老师的精彩讲解. NumPy库入门 数据的维度 维度是一组数据的组 ...
- angular高级篇之transclude使用详解
angular指令的transclude属性是一个让初学者比较难以理解的地方,transclude可以设置为false(默认),true或者对象三种值,如果不设该属性就默认为false,也就是说你不需 ...
- HDFS的接口(命令行接口和Java接口)--笔记
HDFS 文件的系统访问的接口 1.Hadoop的shell命令脚本 hadoop fs -ls 列出某一个目录下的文件 hadoop fs -lsr 递归的方式列出所有文件 hadoop fs ...
- python 3 ---购物车练习
# -*- coding:utf-8 -*-#Author Chen #定义商品列表List_of_commodities = [ ('Iphone',6888), ('Mac Pro',12888) ...
- Java多线程synchronized关键字
synchronized关键字代表着同步的意思,在Java中被synchronized修饰的有三种情况 1.同步代码块 //锁为objsynchronized(obj){ while(true){ i ...
- 淘宝轮播JS
taobao首页轮播原生js面对对象封装版 Author:wyf 2012/2/25
- 表空间与数据文件Offline,online的区别
首先明确,表空间与数据文件的关系:Oracle数据库表空间有两种,一种smallfile小文件表空间(默认),另一种bigfile大文件表空间: 默认表空间与数据文件的关系:允许一对多的处理方式,一个 ...
- spring boot一个简单用户管理DEMO
概述 该Demo旨在部署一个简单spring boot工程,包含数据编辑和查看功能 POM配置 <?xml version="1.0" encoding="UTF- ...
- C#中消息的工作流程
C#中的消息被Application类从应用程序消息队列中取出,然后分发到消息对应的窗体,窗体对象的第一个响应函数是对象中的protected override void WndProc(ref Sy ...
- 《天书夜读:从汇编语言到windows内核编程》七 内核字符串与内存
1)驱动中的字符串使用如下结构: typedef struct _UNICODE_STRING{ USHORT Length; //字符串的长度(字节数) USHORT MaximumLength; ...