设为首页 加入收藏

TOP

Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D 题解(二)
2023-07-23 13:27:35 】 浏览:51
Tags:Codeforces CodeTON Round Div. Rated Prizes A-D 题解
p(i,
1,m) { diff[i] -= 4*(i-1); // 每次两天,一前一后,形成永久隔离,那么里面的自然而然就是不会被感染的了 if(diff[i]) { n -= (diff[i] == 1?1:(diff[i]-1)); } } cout<<n<<endl; } return 0; } void test() { #define mytest #ifdef mytest freopen("ANSWER.txt", "w",stdout); #endif }

D. Magical Array

  大致翻译:

定义一个特殊行,执行操作2,其它行执行操作1(执行次数都至少有一次)

给出这些行,让你输出那个是特殊行,以及特殊行操作2的次数。

解题思路:前缀和和差分,思路简单。

学到了 min_element() max_element()

#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <memory.h>
using namespace std;

#define rep(i,x,n) for(int i = x; i <= n; i++)

typedef long long LL;
typedef pair<int,int> PII;

const int N = 100021;
LL arr[N];
void test();
int main()
{
    //test();
    int t;
    cin>>t;
    while(t--) {
        int n, m;
        scanf("%d %d", &n, &m);
        for(int i = 0; i < n; ++i) {
            LL pre = 0;
            for(int j = 1; j <= m; ++j) {
                LL x;
                scanf("%lld", &x);
                pre += x;
                arr[i] += pre;
            }
        }
        LL mx = *max_element(arr+0, arr+n);
        LL mi = *min_element(arr+0, arr+n);
        cout<< min_element(arr+0, arr+n) - arr + 1<<" "
            <<mx - mi<<endl;
            memset(arr, 0, sizeof(arr));
    }
   

    return 0;
}

void test() {
    #define mytest
    #ifdef mytest
    freopen("ANSWER.txt", "w",stdout);
    #endif
}

总结:学了几个stl

count() --  返回个数 max_element()  min_element()  --  返回迭代器或地址(数组)。

第一次做codeforces,写的时候太着急了,有些题没理解透彻或者复杂化了,A题用时较长。

加油!!!

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C++函数模板和类模板 下一篇Dijkstra算法及其C++实现-云计算..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目