Codeforces 831 C Jury Marks

本文解析了CodeForces上的一道题目C,通过求出评委打分的前缀和并进行排序,利用已知的中间分数来推算可能的初始分数,并采用集合去重的方法确定所有可能的初始得分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目地址:http://codeforces.com/contest/831/problem/C
题意:Polycarp看电视节目,n个评委给参赛选手打分,分别为a1~an。Polycarp 没有记住该位选手的初始分(按时间顺序),只知道m个中间分(不是按时间的顺序),让你求出有多少种初始分。
思路:求出a的前缀和,然后排序,每次以b[0]-a[i]为初始值,然后遍历所有情况,如果全部b都能匹配,就说明该初始值正确,再放入set中去重。

#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define LL long long 
#define N 2010
#define M 50010
#define inf 0x3f3f3f3f
using namespace std;
const LL mod = 1e9 + 7;
const double eps = 1e-9;
LL a[N], b[N];
set<int> s;
int main() {
    cin.sync_with_stdio(false);
    int n, m, q;
    while (cin >> n >> m) {
        s.clear();
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 1; i < n; i++) {
            a[i] += a[i - 1];
        }
        for (int i = 0; i < m; i++) {
            cin >> b[i];
        }
        sort(a, a + n);
        sort(b, b + m);
        int mvp;
        int j, u;
        for (int i = 0; i <= n - m; i++) {
            mvp = b[0] - a[i];
            for (j = 1, u = i + 1; j < m&&u < n;) {
                if (b[j] - a[u] == mvp) {
                    j++;
                    u++;
                }
                else {
                    u++;
                }
            }
            if (j == m) {
                s.insert(mvp);
            }
        }
        cout << s.size() << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值