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 ...
随机推荐
- openerp学习笔记 context 的应用
1.在Action中定义,context用于传递搜索条件和分组条件,在搜索视图中默认显示: 示例代码: <record model="ir.actions.act_window&quo ...
- http server 下载地址
windows 64为位:https://www.apachelounge.com/download/
- Java Socket 模拟HTTP请求
public static void main(String[] args) { try { String url = "192.168.1.103"; Socket socket ...
- [反汇编练习] 160个CrackMe之021
[反汇编练习] 160个CrackMe之021. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...
- operator重载的使用
C++的大多数运算符都可以通过operator来实现重载. 简单的operator+ #include <iostream> using namespace std; class A { ...
- erl0005 - mnesia 分布式部署
http://www.iteye.com/topic/643187 1.启动两个互通的节点a.b: 2.在a节点net_adm:ping(b) 查看ab之间是否联通(nodes()). 3.在保持通的 ...
- qt多文档
http://blog.csdn.net/siren0203/article/details/5661541
- python练习程序(c100经典例12)
题目: 判断101-200之间有多少个素数,并输出所有素数. for i in range(101,201): flag=0; for j in range(2,int(i**(1.0/2))): i ...
- Scala List
1 介绍 Scala中列表List类似于数组,List所有元素都具有相同的类型,但有两个重要的区别. 首先,列表是不可变的,这意味着一个列表的元素可以不被分配来改变. 第二,列表表示一个链表,而数组平 ...
- 【解题报告】[动态规划] RQNOJ PID5 / 能量项链
原题地址:http://www.rqnoj.cn/problem/5 解题思路: 今天刚刚才知道了区间DP..Orz..本来以为是状态压缩DP,后来看到数据量才发现原来不是.后来参考了别人的题解.自己 ...