(CodeForces 558C) CodeForces 558C】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/558/C 题意:给出n个数,让你通过下面两种操作,把它们转换为同一个数.求最少的操作数. 1.ai = ai*2 2.ai = ai/2,向下取整 思路: 可以除以二 或者 乘以二,就相当于位运算的右移和左移.用两个数组,vis 数组, cnt 数组.刚开始都初始化为0: vis[i] 表示 i 这个数可以由几个数转化而来,cnt[i] 表示题目给出的 n 个数全部转化为 i 需要的操作数. 首先遍历数…
https://codeforces.com/problemset/problem/4/C 用来哈希的一道题目,用map也可以强行过,但是性能慢了6倍,说明是在字符串比较的时候花费了接近6倍的时间. 假如时间性能允许的话不妨用map存hash值,这样就可以让他自然溢出了.基数我喜欢选23333,溢出选择ll自然溢出(反正是map存的可以是负的) 自带hash型map,也是慢到感人. #include<bits/stdc++.h> using namespace std; int n; stri…
https://codeforces.com/problemset/problem/327/C 因为答案可以有前导零,所以0和5一视同仁.每个小节内,以排在第 $i$ 个的5为结尾的序列即为在前面 $0\thicksim i-1$ 共i个里面选 $0$ . $1$ . $2$ 直到 $i-1$ 个去除,由二项式定理知道这里是 $2^i$ . 因为小节可以循环,每次循环后面的对应位置要多 $n$ 个元素可以去除,那么就多乘一个 $2^n$ ,而一共有 $k$ 节,由等比数列求和 $\frac{a_…
http://codeforces.com/contest/650/problem/A 一开始想了很久都没有考虑到重复点的影响,解欧拉距离和曼哈顿距离相等可以得到 $x_i=x_j$ 或 $y_i=y_j$ ,假如无重复的话就是分别记录 $x$ 和 $y$ 的值然后 $ans+=mx[i]-1,ans+=my[i]-1$ ,就可以了. 那么有重复的话,有两种解决方法,第一种是分类讨论,就是分重复点和同 $x$ 其他点连.重复点和同 $y$ 其他点连.重复点自己连. #include<bits/s…
https://codeforces.com/problemset/problem/630/H 又一个组合数学的问题,我们先考虑在 $n$ 列中选出 $5$ 列来放椅子,然后对第一列有 $n$ 种放法,第二列有 $n-1$ 种放法……最后就是 $C_n^5A_n^5$ …… 居然没有注意到会溢出,这里可以用大数或者是及时除以因子保证不溢出.因为结果是比较小所以可以试试能不能保证不在64位里溢出. #include<bits/stdc++.h> using namespace std; #def…
Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards…
Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). The i-th fox is ai years old. They will have dinner around some round tables. You want to distribute foxes such that: Each fox is sitting at some table…
In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of ai soldiers. Now soldiers roam. After roaming each soldier has to either stay in his city or to go to the one of neighb…
Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has n cities connected by n - 1 undirected roads, and for any two cities there always exists a path between them. Fox Ciel needs to assign an officer to each city. Each off…
http://codeforces.com/contest/746/problem/D 题意:有n杯茶,a杯绿茶,b杯红茶,问怎么摆放才可以让不超过k杯茶连续摆放,如果不能就输出NO. 思路:首先,设x = min(a,b),y = max(a,b),然后如果(y + x)/(x + 1) > k,那么就输出NO.即把 y 平均分成 x + 1 份,向上取整.然后开始搞... 搞的时候我直接对于 y 每一次都输出最大的份数了,导致后面的 x 过多,还自以为是平均的. 所以应该处理一下,如果有剩余…