Codeforces 799 D. Field expansion】的更多相关文章

题目链接: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的矩阵,要求经过操作使得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就是可行. 然…
[题目链接]:http://codeforces.com/contest/799/problem/D [题意] 给你长方形的两条边h,w; 你每次可以从n个数字中选出一个数字x; 然后把h或w乘上x; 直到能够把一个长为a宽为b的长方形装下为止; 问你最小的数字选择次数; [题解] 把所给的n个数字从大到小排; 显然同样是选一个数字,选大的数字肯定比较优; 问题只是要让哪一条边乘上它; 这里可以知道 如果全都是2的话 最多需要34个数字; 因为log2(100000)≈17 然后两条边都最多需要…
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…
显然将扩张按从大到小排序之后,只有不超过前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 解题关键:因为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,你可以从给出的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/C 题意:要求造2座fountains,可以用钻石,也可以用硬币来造,但是能用的钻石有限,硬币也有限,问能造出最大的美丽值为多少. 题解:显然如果两个fountains分别用钻石和硬币来造的话就直接取两种类型里满足条件的最大值即可. 如果选的是同类的话,先按照数量来排序,然后那一个数量为基准二分下个可行的数量,然后还需要一个 数组来存小于等于某个数量的最大美丽值. #include <iostream>…
A. Carrot Cakes 题面 In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't hav…
题目在这里 A.Carrot Cakes 乱七八糟算出两个时间比较一下就行了 又臭又长仅供参考 #include <bits/stdc++.h> #define rep(i, j, k) for(int i = j;i <= k;i ++) #define rev(i, j, k) for(int i = j;i >= k;i --) using namespace std; typedef long long ll; int main() { ios::sync_with_std…
The Ads Insights API provides API access for reporting and analytics purposes. When exclusively using the Ad Insights API, request the ads_read permission. 1. Marketing API Quickstart 2. Example Query: Campaign Statistics 3. All References #  Next St…
E. Vanya and Field Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/problem/E Description Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with…
"Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 Description Once upon a time there was a greedy King who ordered his chief Architect to build a field for royal cricket inside his park. The King was so…
题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走了n步后,x从0~n-1,y从0~n-1都访问过,但x,y不相同. 所以,x肯定要经过0点,所以我只需要求y点就可以了. i,j为每颗苹果树的位置,设在经过了a步后,i到达了0,j到达了M. 则有 1----------------------(i + b * dx) % n = 0 2------…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates(xi, yi). Van…
A.QAQ 题目大意:从给定的字符串中找出QAQ的个数,三个字母的位置可以不连续 思路:暴力求解,先找到A的位置,往前扫,往后扫寻找Q的个数q1,q2,然 后相乘得到q1*q2,这就是这个A能够找到的QAQ个数,依次累加即可 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin>>s;…
题目链接:https://cn.vjudge.net/problem/CodeForces-894B Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't alway…
894B - Ralph And His Magic Field 思路: 当k为1时,如果n和m奇偶性不同,那么没有答案. 可以证明,在其他情况下有答案,且答案为2^(n-1)*(m-1),因为前n-1行和m-1列确定后,最后一列和最后一行可以确定,且确定的最后一格不矛盾. 可以采用在全为1的格子中把一些1换成-1的方法来证明以上两条结论. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define…
E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the c…
B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on th…
B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on th…
E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the c…
题目链接:https://vjudge.net/problem/CodeForces-385E E. Bear in the Field time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Our bear's forest has a checkered field. The checkered field is an n × n…
E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the c…
题目链接 题意:给你三个数n,m,k;让你构造出一个nm的矩阵,矩阵元素只有两个值(1,-1),且满足每行每列的乘积为k,问你多少个矩阵. 解法:首先,如果n,m奇偶不同,且k=-1时,必然无解: 设n为奇数,m为偶数,且首先要满足每行乘积为-1,那么每行必然有奇数个-1,那么必然会存在有偶数个-1..满足每列乘积为-1,那么每列必然有奇数个-1,那么必然存在奇数个-1.互相矛盾. 剩下的就是有解的情况了. 我们可以在n-1m-1的矩阵中随意放置-1,1.在最后一列和最后一行控制合法性即可. #…
| [链接] 我是链接,点我呀:) [题意] 给你一个n*m矩阵,让你在里面填数字. 使得每一行的数字的乘积都为k; 且每一列的数字的乘积都为k; k只能为1或-1 [题解] 显然每个位置只能填1或-1 如果只考虑前n-1行和前m-1列. 那么我们对这(n-1)*(m-1)的范围. 先任意填入数字; 则一共有\(2^{(n-1)*(m-1)}\)种方法. 然后把最后一行的前m-1列填一下. 使得前m-1列满足,每一列的乘积为k 然后把最后一列的前n-1行填一下使前n-1行每一行的乘积都为k 最后…
Description 给出一个$n\times m$的$01$矩阵$A$. 记矩阵$X$每一个元素取反以后的矩阵为$X'$,(每一个cell 都01倒置) 定义对$n \times m$的矩阵$A$进行一次变幻操作,变幻后矩阵的大小是$2n \times 2m$的. 具体来说,我们会把$A$复制一份到$A$的右下方,计算$A'$并放置在$A$的正右方和正下方. 设连续操作$n$的结果是$f^n(A)$ 即 $f^n(A) = \left\{\begin{matrix} f(f^{n-1}(A)…
传送门:QAQQAQ 题意:给一个01矩阵A,他的相反矩阵为B,每一次变换都会将原矩阵面积乘4成为: AB BA 矩阵的左上角固定,变换无限次,现有q个询问,即求一个矩阵内的1的个数. 思路:因为反转,所以A,B矩阵拼起来刚好是一个全都为1的矩阵,所以答案就是匹配的A,B矩阵总点数/2和右下角1的个数之和 注意点: 1.因为数据较大,要用前缀和思想 2.要开longlong 3.注意询问时各个变量的重置 代码: #include<iostream> #include<cstdio>…