码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 534C Polycarpus' Dice (数学)

时间:2016-08-02 11:19:30      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

题意:第一行给两个数,n 和 A,n 表示有n 个骰子,A表示 n 个骰子掷出的数的和。第二行给出n个数,表示第n个骰子所能掷出的最大的数,这些骰子都有问题,

可能或多或少的掷不出几个数,输出n个骰子掷不出的数的个数。

析:我们只要考虑两个极端就好,考由其他骰子投出的最大值和最小值,还有自身在最大值和最小值,作一个数学运算就OK了。公式如下:

骰子的最大值-能投的最大值+能投的最小值-1.

代码如下:

 

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 2e5 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
    return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn];

int main(){
    LL sum;
    scanf("%d %I64d", &n, &sum);
    LL x = sum;
    for(int i = 0; i < n; ++i){
        scanf("%d", &a[i]);
        sum -= a[i];
    }

    for(int i = 0; i < n; ++i){
        if(i)  putchar(32);
        LL y = sum + a[i];
        LL mmax = min((LL)a[i], x-(n-1));
        LL mmin = max(1LL, y);
        printf("%I64d", a[i]-mmax+mmin-1);
    }
    putchar(10);
    return 0;
}

 

CodeForces 534C Polycarpus' Dice (数学)

标签:

原文地址:http://www.cnblogs.com/dwtfukgv/p/5728213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!