Skip to main content
  1. Posts/

codeforces 534 C Polycarpus' Dice

·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

http://codeforces.com/problemset/problem/534/C

题意是说一共有N个骰子,第I个筛子一共有di面…现在知道这些骰子的点数之和,问对于每一个骰子不能取得值有多少个。

乍一看有点不明觉厉…稍微再想下,求取值范围即可。

先把所有di相加,得到所有骰子点数之和的最大值…然后点数之和的最小值当然就是N

对于每个骰子,将最大值和最小值减去这个骰子的对应数值…然后与总和A进行比较。

注意要开long long !!!

比赛的时候我明明写了typedef。。。结果后面还是忘记了。。。真是悲伤。

 1
 2    /* ***********************************************
 3    Author :111qqz
 4    Created Time :2016年03月03日 星期四 13时54分19秒
 5    File Name :code/cf/problem/534C.cpp
 6    ************************************************ */
 7
 8    #include <iostream>
 9    #include <algorithm>
10    #include <cstring>
11    #include <cmath>
12    #include <cstdio>
13    typedef long long LL;
14    const int N=2E5+7;
15    LL n,d[N],ans[N];
16    LL A,MAX,MIN,TMAX,TMIN;
17
18    using namespace std;
19
20    int main()
21    {
22        scanf("%I64d %I64d",&n,&A);
23        memset(ans,0,sizeof(ans));
24        for ( int i = 1; i <= n ;i ++ )
25            scanf("%I64d",&d[i]);
26        MAX = 0;
27        MIN = n;
28        for ( int i = 1; i <= n ; i++ )
29            MAX = MAX + d[i];
30        for ( int i = 1 ; i <= n ; i++ )
31        {
32            TMAX = MAX - d[i];
33            TMIN = MIN - 1;
34            if (d[i]>=(A-TMIN))
35            {
36                ans[i] =ans[i]+d[i]-(A-TMIN);
37            }
38            if (A>=TMAX+1)
39            {
40                ans[i] =ans[i]+A-TMAX-1;
41            }
42
43        }
44        for ( int i = 1; i < n ; i++)
45            cout<<ans[i]<<" ";
46            cout<<ans[n];
47
48
49        return 0;
50    }

Related

cf 534B. Covered Path

·1 min
http://codeforces.com/problemset/problem/534/B 题意是说一辆车,每秒内的速度恒定…第I秒到第I+1秒的速度变化不超过D。初始速度为V1,末速度为V2,经过时间t,问最远能走多远。

hdu 2138 How many prime numbers

ACM STEPS里的…这题前面一道是求LCM….结果接下来就是这么一道。。。 朴素会超….筛法会爆….题目顺序真是按照难度来的? 于是想到 Miller-Rabin素数测试……. 这个方法是基于费马小定理 我的理解就是… 如果我要判断n是否为素数 只要取k个数 如果满足 a^(n-1)mod n =1 那么n就很可能为素数。 证明什么的…暂时还是算了吧…论文里貌似扯了一大堆 第一次用,竟然真的A了。。。。 感觉更好的办法也许是先打一个比较小的素数表,然后每次random选取若干个进行判断…那样应该更可靠些? 本来想WA掉之后再改的。。。没想到这么写就A掉了。。。。杭电数据略水?

cf 535B Tavas and SaDDas

·1 min
B. Tavas and SaDDas time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn’t stop doing that. That’s why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas’ headphones and told him: “If you solve the following problem, I’ll return it to you.”

codeforces 534 A. Exam

·2 mins
A. Exam time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.

codeforces 479D. Long Jumps

·2 mins
http://codeforces.com/problemset/problem/479/D 题意是说有一把尺子,本身有一些刻度,然后需要测量x和y,问最少需要添加多少个刻度,如果需要,这些刻度分别添加在什么位置。