zoukankan      html  css  js  c++  java
  • Codeforces 895 A Pizza Separation 水题

      题目链接: http://codeforces.com/contest/895/problem/A

      题目描述: 一个圆, 分成连续的两个部分, 问两个部分最小差值是多少? 

      解题思路: 只要找连续和 与180相距最小的就可以 ans 就是它的两倍, 然后用前缀和维护, 数据很小, 所以我直接暴力的

      代码: 

    #include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <list>
    #include <iterator>
    #include <cmath>
    #include <cstring>
    #include <forward_list>
    using namespace std;
    
    const int maxn = 400;
    int a[maxn];
    
    int main() {
        int n;
        cin >> n;
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }    
        if(n == 1) {
            cout << 360 << endl;
            return 0;
        }
        else {
            int min_v = 369;
            for(int i = 0; i < n; i++) {
                for(int j = i; j < n; j++) {
                    int sum = 0;
                    for(int k = i; k <= j; k++) {
                        sum += a[k];
                        min_v = min(min_v, abs(180-sum));
                    }
                }
            }
            cout << 2 * min_v << endl;
        }
        return 0;
    }
    View Code

      思考: 这场CF打的太水了, 太水了, 第一题切出来就挂机了。 明天补B, C题。

  • 相关阅读:
    DataTable四个方法
    c++面向对象编程必备“良方”(转)
    函数调用约定
    AFX_IDW_PANE_FIRST(转)
    CString.Format的详细用法(转)
    ID的分配 (转)
    CString用法整理(转载)
    jquery之效果
    JS 水仙数
    CSS 文本换行
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7923342.html
Copyright © 2011-2022 走看看