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;
}
CodeForces 534C Polycarpus' Dice (数学)的更多相关文章
- 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 ...
- CF Polycarpus' Dice (数学)
Polycarpus' Dice time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 【codeforces 534C】Polycarpus' Dice
[题目链接]:http://codeforces.com/contest/534/problem/C [题意] 给你n个奇怪的骰子,第i个骰子有di个面; 然后给你n个骰子的点数之和; 问你每一个骰子 ...
- hdu - 3959 Board Game Dice(数学)
这道题比赛中没做出来,赛后搞了好久才出来的,严重暴露的我薄弱的数学功底, 这道题要推公式的,,,有类似于1*a+2*a^2+3*a^3+...+n*a^n的数列求和. 最后画了一张纸才把最后的结果推出 ...
- codeforces 687B - Remainders Game 数学相关(互质中国剩余定理)
题意:给你x%ci=bi(x未知),是否能确定x%k的值(k已知) ——数学相关知识: 首先:我们知道一些事情,对于k,假设有ci%k==0,那么一定能确定x%k的值,比如k=5和ci=20,知道x% ...
- Codeforces Gym 100269G Garage 数学
Garage 题目连接: http://codeforces.com/gym/100269/attachments Description Wow! What a lucky day! Your co ...
- Codeforces Round 56-A. Dice Rolling(思维题)
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- Codeforces C. Almost Equal (数学规律)
题目链接:http://codeforces.com/contest/1206/problem/C 题解 : 观察可以发现当n为偶数时,1 - 2n是不满足题意的,可以举例n = 2,n = 4试一试 ...
- codeforces 101C C. Vectors(数学)
题目链接: C. Vectors time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- 博客已搬家至 hate13.com
博客园停止更新,新博客链接:hate13.com 欢迎访问~
- Windows下PhpStorm结合WAMP开发Phalcon应用的配置
最近要利用Phalcon框架开发PHP应用,因为以前基本没接触过PHP更没用过PHP框架,结果整环境整IDE配置什么的花了好长时间 学习慕课网上的PHP入门教程安装了WAMP(windows+apac ...
- hihoCoder #1176 : 欧拉路·一 (简单)
题意:给出n个岛,每个岛都有桥到达其他岛,且桥数可多可少(即使两岛有多桥),判断是否是欧拉路(即每条桥只能走一次,所有桥都能遍历1遍). 思路: 满足如下条件之一者即为欧拉路: 1.连通图,每个岛的度 ...
- ecshop 改变sitemap.xml的位置
大家知道ECSHOP默认的sitemap.xml文件是放置在data文件夹中的,但是这不利于GOOGLE的抓取.我们必须把sitemap.xml文件放置在根目录下 在admin/sitemap.php ...
- 聊聊Oracle 11g的Snapshot Standby Database(上)
Oracle 11g是Data Guard的重要里程碑版本.在11g中,Active DataGuard.Advanced Compression等特性大大丰富了Data Guard的功能和在实践领域 ...
- android中的所谓观察者模式
生活中我们常认定某些人很有才,但什么是有才呢?明朝的王守仁曾这样解释:才,是所谓天理,应用到物上,便成了才.凡事凡物,只要掌握了所谓科学的方法,并能灵活运用,那么你也可以成为一个有才的人. 观察者模式 ...
- Java IO读写大文件的几种方式及测试
读取文件大小:1.45G 第一种,OldIO: public static void oldIOReadFile() throws IOException{ BufferedReader br = n ...
- Eclipse插件安装的三种方法
转自:http://www.blogjava.net/tangzurui/archive/2008/06/30/211669.html 整理了一下格式. (前两种安装方式以多国语言包的安装为例) 1 ...
- php 采集程序 宋正河
本程序主要是通过php采集网页信息,程序自动存储采集进度,采用phpquery简化元素节点匹配,采集到的内容直接入库 你要做的只是写好采集语法,本程序适合有一定php基础的人使用!当然你也可以进行修改 ...
- Epic - Coin Change
Something cost $10.25 and the customer pays with a $20 bill, the program will print out the most eff ...