In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n…
Field expansion [题目链接]Field expansion [题目类型]随机化算法 &题解: 参考自:http://www.cnblogs.com/Dragon-Light/p/6843866.html 这种想法简直让我大开眼界啊, 原来这题还可以这么写!! &代码: #include <cstdio> #include <bitset> #include <iostream> #include <set> #include…
D. Field expansion time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy…
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; ; ull base[maxbit], n, k; void preDeal() { ] = ; ; i < maxbit; i++){ *]; } } voi…
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的货币越优.如有1,2,5,10,20,50,那么我们尽量用面值为1的.如果我们把原始货币换成面值为x的货币,设汇率为d,那么需要的原始货币为dx的倍数.显然dx越小,剩下的钱,即n取模dx会尽量小. 然后就可以枚举换某一种货币的数量,时间复杂度\(O(\frac{n}{d})\) 代码 #inclu…
[CQOI2012]模拟工厂 题解(搜索+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1327574 链接题目地址:洛谷P3161 BZOJ P2667 这个题练一练综合思想还是不错的...(然而蒟蒻不会啊) 做法 肯定是在能完成某些订单的情况下使自己生产力越高越好是吧(一个大致的贪心方向) 但是我们不知道自己到底应该怎么去决定提高生产力时间 那么换个角度,不从时间来看,从订单上来看 贪心 我们假设一定要完成订单\(1-n\) 那么应该如何贪心…
[题目链接]:http://codeforces.com/contest/799/problem/D [题意] 给你长方形的两条边h,w; 你每次可以从n个数字中选出一个数字x; 然后把h或w乘上x; 直到能够把一个长为a宽为b的长方形装下为止; 问你最小的数字选择次数; [题解] 把所给的n个数字从大到小排; 显然同样是选一个数字,选大的数字肯定比较优; 问题只是要让哪一条边乘上它; 这里可以知道 如果全都是2的话 最多需要34个数字; 因为log2(100000)≈17 然后两条边都最多需要…
显然将扩张按从大到小排序之后,只有不超过前34个有效. d[i][j]表示使用前i个扩张,当length为j时,所能得到的最大的width是多少. 然后用二重循环更新即可, d[i][j*A[i]]=max(d[i][j*A[i]],d[i-1][j]); d[i][j]=max(d[i][j],d[i-1][j]*A[i]); 当某次更新时,检验其符合了答案的条件,就输出. 显然可以用滚动数组优化到空间为线性. 注意爆int的问题. 此外,瞎几把搜+花式剪枝也能过. #include<cstd…
题目链接:http://codeforces.com/contest/799/problem/D 因为${a_i>=2}$那么一个数字至多操作${log_{2}^{max(a,b)/min(h,w)}}$之后就会超过给定的${a,b}$,所以可以搜索,考虑复杂度问题我们就直接随机化,显然按照a_i的大小从大往小选. 辣鸡出题人没有把$h,w$旋转$90$度的情况放在PP里面,我的rating啊... #include<iostream> #include<cstdio> #i…
http://codeforces.com/contest/799/problem/D [题意] 给定长方形的两条边h和w,你可以从给出的n个数字中随意选出一个x,把h或者w乘上x(每个x最多用一次),直到能够把一个长为a宽为b的长方形装下为止.问最小的x选择次数. 首先,同样选一个数字,数字大的肯定较优,因此先给x从大到小排序: 现在的问题是同一个x,要给h乘还是w乘. 首先,题目的数据范围是100 000,所以最多只需要34个x(log100 000=17),但是如果这样暴搜的话时间复杂度是…
http://codeforces.com/contest/799/problem/D 解题关键:因为3^11>100000,所以若只把2单独拿出,最多只需要暴力2^11次,故只需要dfs一下即可. #include<bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; typedef long long ll; ll a,b,h,w,n,d[],ans; void dfs(ll aa,ll bb,ll x){ if(aa&…
题目链接:http://codeforces.com/contest/799/problem/D 题意:给出h*w的矩阵,要求经过操作使得h*w的矩阵能够放下a*b的矩阵,操作为:将长或者宽*z[i] 有n个z[i]而且每个z[i]只能用一次. 题解:首先我们知道最少要扩大几倍, x = a / h + (a % h ? 1 : 0); y = b / w + (b % w ? 1 : 0); 当然要先排一下序从大到小,然后再是for一遍 pp *= z[i]; 如果pp>=x*y就是可行. 然…
1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1-9每个字母分别要ai升油漆,问最多可画多大的数字. 贪心,也有点考思维. #include<bits/stdc++.h> using namespace std; #define LL long long #define INF 0x3f3f3f3f int main() { ]; while(…
题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 每个东西在每秒钟都会产生1的能力. 然后问你怎么放才能使得最后能力最大,输出出来 解法: 贪心,最后肯定1越多越好 所以我们放1的时候,注意一下,如果放不下的话,就把其中一个2扔掉,然后放1就好了 //CF gym 100269E #include <bits/stdc++.h> using na…
题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He wants to charge them with Balala Power (he could change each character ranged from a to z into each number ranged from 0 to 25, but each two differen…
考试的时候写了个dfs找出来了,最后处理的时候想到了贪心,但是正确性没有想通.然后想了想动规,也没想通.最后没办法,用状态的话用了个状压,弄了40分. 正解是bfs+贪心.Dfs也有过的. 下面题解引用自他人: 整体的思路是这样的: 从第一层的每一个点开始往下做一次搜索,每一次搜索可以覆盖到最后一行的一段,我们就可以把它看成是一条线段: 做完搜索之后我们就得到了一坨线段..然后这就变成了一个线段覆盖问题,用最少的线段来把最后一行盖满,当然也存在无论如何都盖不满的情况.. 下面来说说线段覆盖的思路…
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾.(2)把t的尾字符取出并添加到u的末尾. 问你当经过一系列操作后,s和t均为空时,字典序最小的u. 题解: 操作的本质: s为队列,t为栈. 贪心思路: (1)找到s中的最小字符c,不断出队并加入t,直至有一次出队的字符等于c,停止出队. (2)当t的尾字符小于等于s中的最小字符时,优先弹出t的尾…
Magazine Ad 题目链接:http://codeforces.com/contest/803/problem/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个数字k,和一行字符 例: garage for sa-le 其中这行字符串能够在 ' '与'-'的后面分割.例如分割为:(点代表空格) garage. for. sa- le 求:分割成不超过k行的情况下的最小宽度.(宽度:最大行的字符个数) 思路: 答案一定在 到 所给字符串长度 之间. ①通过二分宽度 来逼近最小宽度. 判…
原文链接https://www.cnblogs.com/zhouzhendong/p/9074226.html 题目传送门 - Codeforces 980E 题意 $\rm Codeforces$ 真是个令人伤心的地方. 伤心的 $zzd$ 给你一个有 $n$ 个节点的树,编号为 $i$ 的节点权值为 $2^i$. 让你砍掉其中 $k$ 个节点,使得剩余的所有节点都连通,并最大化剩余节点的权值和.输出方案. $n\leq 10^6$ 题解 伤心的 $zzd$ 再一次来到了令人伤心的 $\rm…
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, …
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes. A string is 1-palindrome if and only if it reads the same backward as f…
C. NP-Hard Problem time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very int…
题目链接:http://codeforces.com/problemset/problem/402/D 题意: 给你一个长度为n的数列a[i],又给出了m个“坏质数”b[i]. 定义函数f(s),其中p是s的最小质因子: f(1) = 0 f(s) = f(s/p) + 1 (p不是坏质数) f(s) = f(s/p) - 1 (p是坏质数) 你可以任意次数地进行操作:给a[1 to i]的每个数都除以gcd(a[1 to i]). 问你 ∑ f(a[i)最大为多少. 题解: 函数f(s)的实际…
题目:https://www.luogu.org/problemnew/show/P2540 发现如果没有顺子,剩下的可以贪心.所以搜索顺子怎么出,然后贪心. 这样只能过不加强版.原因是贪心的时候难以弄3=1+2.3应该是 3带* 还是拆开让4带上? 如这个数据(×后面是个数):3×3,4×1,6×4,7×3,9×1,10×2,11×1,12×4,13×3 正解应该是把一个3拆成1+2,然后两次4带2,两次3带2.但贪心似乎做不了. 所以应该dp!记录1,2,3,4,王各有几个,就能把“拆”体现…
Waca loves maths,.. a lot. He always think that 1 is an unique number. After playing in hours, Waca suddenly realize that every integer can be represented by digit '1', plus operator and minus operator. For example, 1534 can be represented as 1111 +…
题目:https://www.luogu.org/problemnew/show/P2668   https://www.luogu.org/problemnew/show/P2540 首先,如果没有顺子,那么有贪心最优解: 所以先搜索顺子,再贪心求剩余的出牌方案: 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace s…
Walk Out Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 141    Accepted Submission(s): 17 Problem Description In an n∗m maze, the right-bottom corner is the exit (position (n,m) is the exit).…
题目链接:http://codeforces.com/contest/233/problem/C 题意:在一个无相图中有N个长度为3 的回路,输出符合条件的图.注意此图的节点数不得超过100 题解:贪心即可具体怎么贪心看代码. #include <iostream> #include <cstring> using namespace std; bool vis[120][120]; int main() { int k , n; cin >> k; memset(vi…
Codeforces Global Round 2 题目链接: E. Pavel and Triangles Pavel has several sticks with lengths equal to powers of two. He has \(a_0\) sticks of length \(2^0=1\), \(a1\) sticks of length \(2^1=2\), ..., \(a_{n−1}\) sticks of length \(2^{n−1}\). Pavel wa…
B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进行一种特殊的排序,使得数组中相邻的两个数的差的绝对值成非递减趋势: 2.刚开始对这道题总是执拗于两个相等的数在不同位置,如何把它们放到前面这个问题,因为路走歪了,最终无果,没有思路.后来看了一些关于这道题的解题博客,豁然开朗. 3.使得数组中相邻的两个数的差的绝对值成非递减趋势,怎么想呢.单纯想怎么…