Codeforces 479B. Towers 暴力】的更多相关文章

纯暴力..... B. Towers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same si…
题目链接:http://codeforces.com/problemset/problem/479/B 题目意思:有 n 座塔,第 i 座塔有 ai 个cubes在上面.规定每一次操作是从最多 cubes 的塔中取走一个cube,加去拥有最少 cubes 的塔上,那么显然,本来是最多cubes的塔的 cubes 数目会减少1,而拥有最少的 cubes 的塔的cubes数增加 1 .现在最多操作 k 次,使得最多 cubes 数 的塔的cubes数 减去 最少cubes数的塔的cubes 数最少(…
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and mcolumns. Each cell originally contains the number 0. One move consists of choosing one row or c…
Chladni Figure CodeForces - 1162D Inaka has a disc, the circumference of which is nn units. The circumference is equally divided by nn points numbered clockwise from 11 to nn, such that points ii and i+1i+1 (1≤i<n1≤i<n) are adjacent, and so are poin…
http://codeforces.com/problemset/problem/229/D 题意:有n(1<=n<=5,000)座塔排在一条直线上,从左到右每个塔的高度分别为hi(1<=hi<=100,000),每次操作你可以选择一座塔(假设是第i座),用吊车把它吊起来,然后放到与它相邻的一座塔上(可以是第i-1座也可以是第i+1座),这样,新塔的高度为两座塔的和,完成操作后,塔的总数减少一座.问最少需要多少次操作可以使得所有的塔从左到右形成一个非递减序列. 思路: 我们可以这样…
The only difference between easy and hard versions is a number of elements in the array. You are given an array aa consisting of nn integers. The value of the ii-th element of the array is aiai. You are also given a set of mm segments. The jj-th segm…
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人只能打招呼一次). 例: 输入:31 1 105 8 29 9 10 输出: 2 1 1 解题思路:先按行走的开始时刻排下序,然后直接模拟判断和比他后出现的人是否可以相遇. 第一步判断前面那个人在未走完前,下一人会出现,若不出现,直接break.然后就计算当下一个人出现的时刻,前一个人的位置,然后又…
题目链接:http://codeforces.com/problemset/problem/589/B 题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分,宽度也同样,求出可以得到多少个一样(每个矩形的长相等,宽也相等)的矩形,使得面积之和最大,并输出长和宽. 解题思路:将每个矩形的长和宽都存到一个结构体数组内,对矩形的长进行排序,因为最终结果的长一定是某个矩形的长,宽也一定是某个矩形的宽,所以我们枚举长,然后将长大于等于该长度的矩形的宽加入到一个向…
Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n rectangular cake layers. The length and the width of the i-th cake layer were ai and birespectively, while the height of each cake layer was equal to…
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum_{i = 1}^{n} a_{i} \leqslant K$的最大正整数$d$. 整理一下可以得到条件是$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil \leqslant K + \sum_{i = 1}^{n} a_{i}$…
A. Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you…
A. Cookies time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there…
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cma…
Sum of sequencesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86686#problem/B Description You finished RIUSB ACBJSO university few years ago and started working hard and growing your carrier. At th…
题意:1000个元素,每个元素的大小-1e9<=a[i]<=1e9,然后让你重新安排这些元素的位置 获得最长的前缀斐波那契数列 分析:枚举第一个元素和第二个元素,因为在题目元素的范围内,最多形成长度为90的斐波那契数列 除非有全0的情况出现,这种情况会达到长度1000 所以这种情况特判一下(记录一下零元素的个数就行了) 然后枚举是n^2的 找元素是90,然后找的时候,我用的map来找 所以时间复杂度是略大是O(90n^2logn) 所以由于不可能每次都找到90,所以均摊比较小,这题时限是3s,…
A. Cifera time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned…
题意: 在一个从0开始的连续区间上  放置几个小区间,使得这些小区间覆盖整个大区间,不同长度的小区间有不同的花费,其中有m个点,小区间的左端点不能放在这些点上 解析: 显然如果0是这m点中的一个 则无解 然后就是标记上连续不能放的点  然后遍历每一个小区间  从0开始放 求花费最小值即可 · 注意最大值的设置 代码都加了1,从1开始 #include <bits/stdc++.h> using namespace std; , INF = 0x7fffffffffffffff;; typede…
LINK 题目大意:给你n个数,你可以交换一个数的任意二进制位,问你可以选出多少区间经过操作后异或和是0 思路 充分必要条件: 区间中二进制1的个数是偶数 区间中二进制位最多的一个数的二进制个数小于等于和的一半 然后因为每个数最少会贡献1,所以直接暴力向前跳128位,再之前的就直接前缀和做掉就可以了 #include<bits/stdc++.h> using namespace std; #define LL long long #define IL inline #define fu(a,b…
题意: 要生产n个物品,每个花费时间为x. 有两种魔法,每种最多使用1个. 其中第一种魔法可以使每个物品生产的花费时间变为ai,相应的花费是bi;第二种魔法可以减少ci个物品,相应的花费是di,并且保证对于i<j ci<=cj 且 di<=dj; #include<bits/stdc++.h> using namespace std; ],c[],d[]; pair<]; long long inf=0x3f3f3f3f3f3f3f3f; int main() { lo…
题意: 给你的一个十进制数n,计算对于2~n-1进制下的每个位相加和与数n-2的比值. 思路: n是1000,所以直接暴力一发? #include<cstdio> #include<iostream> #include<string.h> #include<algorithm> using namespace std; typedef long long LL; const int N=1e5+10; int solve(int n,int x) { int…
题意: 有n个数字, 要求在这n个数中选出至少两个数字, 使得它们的和在L,R之间,并且最大的与最小的差值要不小于x 思路: 撒比了啊... 根据状态的话一共也就是2^15-直接暴力,二进制的小魅力还是没能领会: code-- #include <bits/stdc++.h> #include<algorithm> using namespace std; typedef long long LL; const int N=1e6+10; int a[20]; int main()…
题意 https://vjudge.net/problem/CodeForces-1228D 有一个n个顶点m条边的无向图,在一对顶点中最多有一条边. 设v1,v2是两个不相交的非空子集,当满足以下条件时f(v1,v2)为真 v1中的点之间不存在边 v2中的点之间不存在边 对于在v1v2中的每一对顶点,x在v1中,y在v2中,xy之间有边 所有点集不为空,且不相交,是否有v1,v2,v3使得f(v1,v2).f(v2,v3).f(v3,v1)均为真 如果有输出每个点所在的点集(1,2,3),否则…
题目链接 思路如下 *题意: 给定一个序列,问有多少种方案可以将此序列分割成3个序列元素和完全相同的子序列.(子序列不能为空).即问有多少个点对(i,j)满足a[1]+-+a[i-1]=a[i]+a[i+1]+-+a[j]=a[j+1]+a[j+2]+-+a[n] 思路:这一题直接暴力求解就行了 看 n是否小于3 或者 数列元素之和 不能被3整除,如果是直接输出 0 当我们考虑某个位置 J 的时候,如果该位置的前缀和 sum[ J ] 是序列前缀和sum[ n ]的三分之二(此时剩下的区间的和一…
题目链接:http://codeforces.com/problemset/problem/724/B 题目大意: 给出N*M矩阵,对于该矩阵有两种操作: (保证,每行输入的数是 1-m 之间的数且不重复) 1.交换两列,对于整个矩阵只能操作一次 2.每行交换两个数. 交换后是否可以使每行都是1-m 数字递增. 解题思路: 1.得到矩阵后先判断,是否每行可以交换两个数可以得到递增的矩阵,如果可以则输出"YES". 2.暴力交换两列,交换两列后,判断每行是否可以交换两个数得到递增的矩阵,…
今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you fin…
题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一个满足条件的四个点. 题解: 首先预处理出任意两点的最短距离,用队列优化的spfa跑:O(n*n*logn) 现依次访问四个点:v1,v2,v3,v4 我们可以枚举v2,v3,然后求出v2的最远点v1,v3的最远点v4,为了保证这四个点的不同,直接用最远点会错,v1,v4相同时还要考虑次最远点来替换…
题目链接:http://codeforces.com/problemset/problem/27/E 暴力 //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #includ…
There is No Alternative 题目连接: http://codeforces.com/gym/100803/attachments Description ICPC (Isles of Coral Park City) consist of several beautiful islands. The citizens requested construction of bridges between islands to resolve inconveniences of u…
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hacking skills to the test! You've been called upon to help crack enemy codes in the current war on... something or another. Anyway, the point is that yo…
C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/problem/C Description You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leadin…