【题目链接】: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. [Angular & Web] Retrieve user data from Session

    Once user sign up, we store the user data inside cookie in the broswer and also keep a memory copy i ...

  2. 彻底搞懂HashMap,HashTable,ConcurrentHashMap之关联.

    注: 今天看到的一篇讲hashMap,hashTable,concurrentHashMap很透彻的一篇文章, 感谢原作者的分享.  原文地址: http://blog.csdn.net/zhange ...

  3. SQL Server2008 Hierarchyid数据类型

    以往我们在关系数据库中建立树状结构的时候,通常使用ID+ParentID来实现两条 纪录间的父子关系.但这种方式只能标示其相对位置.解决这类问题在SqlServer2005出现之前通常是采用游标来操作 ...

  4. 【AtCoder Beginner Contest 074 C】Sugar Water

    [链接]h在这里写链接 [题意] 让你在杯子里加糖或加水. (4种操作类型) 糖或水之间有一定关系. 糖和水的总量也有限制. 问你糖水浓度的最大时,糖和糖水的量. [题解] 写个dfs就好. 每次有4 ...

  5. Android 中AIDL的使用与理解

    AIDL的使用: 最常见的aidl的使用就是Service的跨进程通信了,那么我们就写一个Activity和Service的跨进程通信吧. 首先,我们就在AS里面新建一个aidl文件(ps:现在AS建 ...

  6. 开发板 视频04_05 ubuntu的联网及基本设置

    4g内存 如果电脑有两g,只能给1.5g 处理器可以根据实际选 usb3.0 或者 2.0 联网模式:: 桥接模式 启动式连接,,,,网是不固定的 仅主机模式,主机和虚拟机在一个网络 第三种联网,自定 ...

  7. 9.5 Binder系统_驱动情景分析_transaction_stack机制

    参考文章:http://www.cnblogs.com/samchen2009/p/3316001.html test_server服务进程可能有多个线程,而在发送数据的时候handle只表示了那个进 ...

  8. Vertx简介

    今天看了一篇很不错的关于Vertx的简介,转载下. 原文链接:http://www.csdn.net/article/2015-12-21/2826533?utm_source=tuicool& ...

  9. MySQL的安装及使用教程

    MySQL的安装及使用教程 一.  MySQL的下载及安装 首先登陆MySQL的官网,选择Downloads→Windows→MySQL Installer→Windows(x86,32-bit),M ...

  10. nginx 代理服务器

    目前现状:只有1个机器能上网(web),其他机器不能方法:能上网的做一个代理web服务器中转,其他机器连接它即可。采用nginxNginx配置如下:server{        resolver 8. ...