【题目链接】:http://codeforces.com/contest/534/problem/C

【题意】



给你n个奇怪的骰子,第i个骰子有di个面;

然后给你n个骰子的点数之和;

问你每一个骰子有哪一些面是不可能出现的;

【题解】



对于第i个骰子

设它的点数为x

设其他n-1个骰子的最大点数之和(即∑di)为restmax

如果

x+restmax< A

且x是最大的满足这个条件的x;

则1..x这些点数都不能出现;

同时还有

设其他n-1个骰子的最小点数之和(即n-1)为restmin

如果

x+restmin >A

且x是最小的满足这个条件的x

则x..d[i]这些点数都不能出现;

这里的两个x其实都能直接算出来。。

我写了个二分求。。

所以复杂度应该可以做到O(N)的;不用加上那个对数的;



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 2e5+100; LL n, A;
LL d[N],restmax,restmin; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rel(n), rel(A);
rep1(i, 1, n)
{
rel(d[i]);
restmax += d[i];
}
restmin = n;
rep1(i, 1, n)
{
restmax -= d[i], restmin--;
LL x1 = 0,x2 = d[i]+1;
LL l = 0, r = d[i] + 1;
while (l <= r)
{
LL m = (l + r) >> 1;
if (m + restmax < A)
{
x1 = m;
l = m + 1;
}
else
r = m - 1;
}
l = 0, r = d[i] + 1;
while (l <= r)
{
LL m = (l + r) >> 1;
if (m + restmin > A)
{
x2 = m;
r = m - 1;
}
else
l = m + 1;
}
//1..x1都不行
//x2..d[i]都不行
if (x1 >= x2)
printf("%lld", d[i]);
else
{
printf("%lld", x1 + d[i] - x2 + 1);
}
if (i == n)
puts("");
else
putchar(' ');
restmax += d[i], restmin++;
}
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 534C】Polycarpus' Dice的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. The Swift Programming Language 中文翻译版

    原文(http://www.cnblogs.com/lkvt/p/3765349.html) 一.Welcome to Swift 1.关于Swift Swift是一种用于iOS和OS X应用的全新编 ...

  2. python基础-合并列表

    1.append()  向列表尾部追加一个新元素,列表只占一个索引位,在原有列表上增加 2.extend() 向列表尾部追加一个列表,将列表中的每个元素都追加进来,在原有列表上增加 3.+  直接用+ ...

  3. P2P平台很赚钱么?

    最近几年,搞P2P网贷和财富投资相关的金融周边公司,多了很多,楼下门店和电梯里的贷款小广告,真是多啊. 大家都去搞一件事的时候,很可能是大家都觉得这件事有利可图.但事实是,赚钱的总是少数,看到别人搞的 ...

  4. ThreadPoolExecutor – Java Thread Pool Example(如何使用Executor框架创建一个线程池)

    Java thread pool manages the pool of worker threads, it contains a queue that keeps tasks waiting to ...

  5. IIS服务器设置http自动跳转https方法

    很多站长在部署SSL证书后,网站实现https加密访问,但考虑到用户习惯了http访问,很多外链也是http访问形式,所以需要在IIS服务器配置http自动跳转https,避免用户通过http访问不到 ...

  6. UVA 11090 - Going in Cycle!! SPFA

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  7. 【习题 5-11 UVA 12504 】Updating a Dictionary

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 不确定某个map里面是否有某个关键字的时候. 要用find来确定. 如果直接用访问下标的形式去做的话. 会强行给他加一个那个关键字( ...

  8. chrome-extensions -- copytables. verygood

    https://www.crx4chrome.com/extensions/ekdpkppgmlalfkphpibadldikjimijon/,通过设置快捷键,一般是拷贝多行

  9. Linux 系统 杀Oracle 进程

    Linux 系统 杀Oracle 进程 杀掉进程用此方法比较好,能保证杀得干净,而不是用SQL  alter system kill kill -9 `ps -ef|grep "oracle ...

  10. C语言数组初始化的问题