CodeForces 534C - Polycarpus' Dice(思路)

题意:给定n (1 <= n <= 2*10^5) 个骰子,给定每个骰子最大可以掷出的最大数(最小数始终为1),给定所有骰子掷出的点数和A,求每个骰子不可能掷出的点数个数。

考虑最大和最小情况,作差即可(详情见代码注释)

 

#include<cstdio>  
#include<cstring>  
#include<cctype>  
#include<cstdlib>  
#include<cmath>  
#include<iostream>  
#include<sstream>  
#include<iterator>  
#include<algorithm>  
#include<string>  
#include<vector>  
#include<set>  
#include<map>  
#include<deque>  
#include<queue>  
#include<stack>  
#include<list>  
typedef long long ll;  
typedef unsigned long long llu;  
const int MAXN = 100 + 10;  
const int MAXT = 200000 + 10;  
const int INF = 0x7f7f7f7f;  
const double pi = acos(-1.0);  
const double EPS = 1e-6;  
using namespace std;  
  
int n;  
ll a[MAXT], A;  
  
  
  
int main(){  
    scanf("%d%I64d", &n, &A);  
    ll allsum = 0;                      //所有骰子最大值加起来的总最大值  
    for(int i = 0; i < n; ++i){  
        scanf("%I64d", a + i);  
        allsum += a[i];  
    }  
    for(int i = 0; i < n; ++i){  
        ll down = max(1ll, A - (allsum - a[i]));    //骰子最小值 = 需要的和 - 其他骰子已经全部最大的值  
        ll up = min(a[i], A - (n - 1));             //骰子最大值 = 需要的和 - 其他骰子全部最小值  
        if(i)  printf(" ");  
        printf("%I64d", a[i] - (up - down + 1));    //不可能出现的数 = 总共可以表示的数 - 已经能表示的数  
    }  
    return 0;  
}  

 

转载于:https://www.cnblogs.com/tyty-TianTengtt/p/5996012.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值