zoukankan      html  css  js  c++  java
  • CodeForces 534C Polycarpus' Dice (数学)

    题意:第一行给两个数,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;
    }
    
  • 相关阅读:
    EF基于方法的查询语法
    &,^,|,的简化计算与理解
    会计中阿拉伯数字变数字繁体大写
    接口对接请求方法
    经验总结之Android framework开发
    android开机过程简单描述
    为什么一个类的全局变量默认以m开头?
    使用DataOutputStream写入int类型数字不能显示
    20151128学习总结
    sky简介
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5728213.html
Copyright © 2011-2022 走看看