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 枚举的更多相关文章

  1. 895A. Pizza Separation#分披萨问题(前缀和)

    题目出处:http://codeforces.com/problemset/problem/895/A 题目大意:对于给出的一些角度的披萨分成两份,取最小角度差 #include<stdio.h ...

  2. 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 ...

  3. CodeForces:#448 div2 a Pizza Separation

    传送门:http://codeforces.com/contest/895/problem/A A. Pizza Separation time limit per test1 second memo ...

  4. Codeforces 895.A Pizza Separation

    A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. #448 div2 a Pizza Separation

    A. Pizza Separation time limit per test1 second memory limit per test256 megabytes inputstandard inp ...

  6. Educational Codeforces Round 61 C 枚举 + 差分前缀和

    https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多 ...

  7. Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)

    Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...

  8. CodeForces 617C【序枚举】

    题意: 有两个点喷水,有很多个点有花,给出坐标. 求使得每个花都可以被喷到,两个喷水的半径的平方的和最小是多少. 思路: 枚举其中一个喷水的最大半径. 坑: 这题我贪心的思路有很大问题.一开始也是想这 ...

  9. codeforces 613B B. Skills(枚举+二分+贪心)

    题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. Yii2之类自动加载

    在yii中,程序中需要使用到的类无需事先加载其类文件,在使用的时候才自动定位类文件位置并加载之,这么高效的运行方式得益于yii的类自动加载机制. Yii的类自动加载实际上使用的是PHP的类自动加载,所 ...

  2. LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal (用中序和后序树遍历来建立二叉树)

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  3. 【机器学习】支持向量机(SVM)

    感谢中国人民大学胡鹤老师,课程深入浅出,非常好 关于SVM 可以做线性分类.非线性分类.线性回归等,相比逻辑回归.线性回归.决策树等模型(非神经网络)功效最好 传统线性分类:选出两堆数据的质心,并做中 ...

  4. JF厂V8版本爱彼AP15703,黄家橡树离岸型,超越N厂神器

    根据调查的结果JF厂的爱彼AP15703几乎常年垄断了爱彼的市场,销量持续性的排在爱彼整个品牌中的第一位.JF厂这两年一直在攻克爱彼整个品牌,有了解的都知道 爱彼15703以前是N厂的五大复刻神器的代 ...

  5. Apache和Tomcat整合(一个Apache 不同域名处理多个不同业务)

    一.简介 在项目中,几乎任何一个项目都包括静态资源和动态请求两大部分.特别对于门户网站这样的项目,静态内容资源会更多,我们使用一般的 Tomcat 部署时,Tomcat 对静态资源的处理能力比较慢,至 ...

  6. Cable master

    Problem Description Inhabitants of the Wonderland have decided to hold a regional programming contes ...

  7. Code Lock

    Code Lock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Su ...

  8. curl模拟带验证码的登录

    首先说明,不是用php自动识别验证码,而是有验证码的情况下,让你通过curl 带着cookies去请求远程资源,从而通过合法的身份验证.主要用来抓取需要登录后才能访问的资源. 思路就是获取到验证码之后 ...

  9. 实现验证码图像文字的识别(C#调用DLL)

    请先下载http://asprise.com/product/ocr/index.php?lang=csharp 的SDK.里面提供了详细的OCR方法,如下:   将发现图像框picbVeryfyCo ...

  10. 很考验人的java内存加载面试题

    源代码如下,求结果 public class MemoryAnalyse { public static int k = 0; public static MemoryAnalyse t1 = new ...