题意:第一行给两个数,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 (数学)的更多相关文章

  1. Codeforces Round #298 (Div. 2) C. Polycarpus' Dice 数学

    C. Polycarpus' Dice Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/p ...

  2. CF Polycarpus' Dice (数学)

    Polycarpus' Dice time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  3. 【codeforces 534C】Polycarpus' Dice

    [题目链接]:http://codeforces.com/contest/534/problem/C [题意] 给你n个奇怪的骰子,第i个骰子有di个面; 然后给你n个骰子的点数之和; 问你每一个骰子 ...

  4. hdu - 3959 Board Game Dice(数学)

    这道题比赛中没做出来,赛后搞了好久才出来的,严重暴露的我薄弱的数学功底, 这道题要推公式的,,,有类似于1*a+2*a^2+3*a^3+...+n*a^n的数列求和. 最后画了一张纸才把最后的结果推出 ...

  5. codeforces 687B - Remainders Game 数学相关(互质中国剩余定理)

    题意:给你x%ci=bi(x未知),是否能确定x%k的值(k已知) ——数学相关知识: 首先:我们知道一些事情,对于k,假设有ci%k==0,那么一定能确定x%k的值,比如k=5和ci=20,知道x% ...

  6. Codeforces Gym 100269G Garage 数学

    Garage 题目连接: http://codeforces.com/gym/100269/attachments Description Wow! What a lucky day! Your co ...

  7. Codeforces Round 56-A. Dice Rolling(思维题)

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  8. Codeforces C. Almost Equal (数学规律)

    题目链接:http://codeforces.com/contest/1206/problem/C 题解 : 观察可以发现当n为偶数时,1 - 2n是不满足题意的,可以举例n = 2,n = 4试一试 ...

  9. codeforces 101C C. Vectors(数学)

    题目链接: C. Vectors time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. Codeforces 279 B Books

    题意:给出n本书,总的时间t,每本书的阅读时间a[i],必须按照顺序来阅读,问最多能够阅读多少本书 有点像紫书的第七章讲的那个滑动区间貌似 维护一个区间的消耗的时间小于等于t,然后维护一个区间的最大值 ...

  2. Context上下文对象(抄书的)

    Servlet上下文 ServletContext 上下文接口    ServletContext接口    每一个应用都有唯一的一个上下文对象,即为ServletContext对象    Servl ...

  3. 修改Android系统字号(一)

    /*********************************************************************** * 修改Android系统字号(一) * 说明: * ...

  4. MAC自动备份数据到服务器

    需求:公司内部使用自己电脑,回家需要使用另一台电脑,所以想时时备份公司用的电脑中文件.代码到服务器上,回家就可以用啦 1 无密码使用scp (1)第一步:生成密匙对,我用的是rsa的密钥.使用命令 & ...

  5. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:4.安装Oracle RAC FAQ-4.1.系统界面报错Gnome

    1.错误信息:登录系统后,屏幕弹出几个错误对话框,无菜单.无按钮 GConf error: Failed to contact configuration server; some possible ...

  6. 解析AFNetWorking 网络框架(二)

    转:http://blog.csdn.net/andy_jiangbin/article/details/17114989 接着前面写. 本帖先讲AFURLConnectionOperation,它是 ...

  7. arcgis for android 无法加载本地jpg影像解决办法

    因为jpg影像没有生成金子塔文件*.rrd 一个完整的JPG影像必须包括如下文件: K-50-96-(16).aux  辅助文件K-50-96-(16).jgw  坐标信息K-50-96-(16).j ...

  8. AndroidManifest修改重打包全过程

    AndroidManifest修改重打包全过程: 作者: 蔡建良 2013-06-26 准备工具:apktool.jar和signapk.jar 下载: http://download.csdn.ne ...

  9. Symfony2学习笔记之数据库操作

    数据库和Doctrine让我们来面对这个对于任何应用程序来说最为普遍最具挑战性的任务,从数据库中读取和持久化数据信息.幸运的是,Symfony和Doctrine进行了集成,Doctrine类库全部目标 ...

  10. source 命令

    作用: 当我修改了/etc/profile文件,我想让它立刻生效,而不用重新登录:这时就想到用source命令,如:source /etc/profile 介绍:source命令也称为“点命令”,也就 ...