• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
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;
}

 

posted on 2016-08-02 10:07  dwtfukgv  阅读(274)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3