CoderForces-Round60D(1117) Magic Gems】的更多相关文章

D. Magic Gems time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Reziba has many magic gems. Each magic gem can be split into MM normal gems. The amount of space each magic (and normal) gem t…
Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec Problem Description Input The input contains a single line consisting of 2 integers N and M (1≤N≤10^18, 2≤M≤100). Output Print one integer, the total n…
CF1117D Magic Gems 考虑 \(dp\) , \(f[i]\) 表示用 \(i\) 个单位空间的方案数,答案即为 \(f[n]\). 对于一个位置,我们可以放 \(Magic\) 的,占 \(m\) 空间,也可以放 \(Normal\) 的,占 \(1\) 空间. 转移方程即为 \(f[i]=f[i-1]+f[i-m]\) ,边界条件为 \(f[0]=f[1]=f[2]=\dots f[m-1]=1\). 直接转移是 \(O(n)\) 的,无法通过,需要矩阵优化. 时间复杂度为…
传送门:Educational Codeforces Round 60 – D   题意: 给定N,M(n <1e18,m <= 100) 一个magic gem可以分裂成M个普通的gem,现在需要N个gem,可以选择一定的magic gem,指定每一个分裂或不分裂,问一共有多少种方案 两种分裂方案不同当且仅当magic gem的数量不同,或者分裂的magic gem的索引不同. 思路: 1.首先从dp的角度出发 设F(i)为最终需要i个gem的方案数,容易得到递推式: (总方案数 = 最右边…
https://codeforces.com/contest/1117/problem/D 题解:有一些魔法宝石,魔法宝石可以分成m个普通宝石,每个宝石(包括魔法宝石)占用1个空间,让你求占用n个空间的方法有几种,有不同数量的魔法宝石和不同分法的方法算不同的方法, 分析:根据一些猜想可以推出递推式f[n]=f[n-1]+f[n-m]  : 答案也比较好猜想,牺牲一个然后分解 m 个 然后就是简单的构造矩阵快速幂 或者使用无敌杜教 这里给出点杜教心得 , 有时候并不是只用给出8项 , 而是给的数据…
易得递推式为f[i]=f[i-1]+f[i-M] 最终答案即为f[N]. 由于N很大,用矩阵快速幂求解. code: #include<bits/stdc++.h> using namespace std; typedef long long ll; const int MOD=1e9+7; ll n,m; struct mat { ll a[105][105]; }; mat mat_mul(mat x,mat y) { mat res; memset(res.a,0,sizeof(res.…
题目传送门 题意: 一个魔法水晶可以分裂成m个水晶,求放满n个水晶的方案数(mol1e9+7) 思路: 线性dp,dp[i]=dp[i]+dp[i-m]; 由于n到1e18,所以要用到矩阵快速幂优化 注意初始化 代码: #include<bits/stdc++.h> using namespace std; #define mod 1000000007 typedef long long ll; #define MAX 105 ;//矩阵的大小 int T; ll n,m; ll add(ll…
题目大意: 给定n m (1≤N≤1e18, 2≤M≤100) 一个魔法水晶可以分裂成连续的m个普通水晶 求用水晶放慢n个位置的方案modulo 1000000007 (1e9+7) input 4 2 output 5   设1为魔法水晶 0为普通水晶 n=4 m=2有5种方案 即 1111.0011.1001.1100.0000   得到递推公式 当 i < m 时 dp[ i ] = 1 当 i >= m 时 dp[ i ] = dp[ i-1 ] + dp[ i-m ] n的范围是1e…
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best Subsegment 题意: 给出n个数,选取一段区间[l,r],满足(al+...+ar)/(r-l+1)最大,这里l<=r,并且满足区间长度尽可能大. 题解: 因为l可以等于r,所以我们可以直接考虑最大值,因为题目要求,直接求连续的最大值的长度就是了. 代码如下: #include <bits…
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N magic gems. N of them have Yin energy inside while others have Yang energy. SJX wants to make a necklace with these magic gems for his beloved BHB. To avoid…
Problem Description SJX has 2*N magic gems. N of them have Yin energy inside while others have Yang energy. SJX wants to make a necklace with these magic gems for his beloved BHB. To avoid making the necklace too Yin or too Yang, he must place these…
Necklace Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2423    Accepted Submission(s): 766 Problem Description SJX has 2*N magic gems. N of them have Yin energy inside while others have Yang e…
CF1155D - Beautiful Array 题意:给你一个序列和x,你可以选择任意一个子串(可以为空)乘上x,使得得到的序列最大子串和最大.求这个最大值.30w,2s. 解:设fi,0/1/2表示序列前i个数还没乘x/正在乘x/乘完了x的最大后缀和.答案就是这个DP数组的最大值. #include <bits/stdc++.h> typedef long long LL; ; LL a[N], x, f[N][]; int n; int main() { scanf("%d%…
A. Best Subsegment 题意 找 连续区间的平均值  满足最大情况下的最长长度 思路:就是看有几个连续的最大值 #include<bits/stdc++.h> using namespace std; ; int a[maxn]; int main(){ int n; scanf("%d",&n); ; ;i<n;i++)scanf("%d",&a[i]),maxnum=max(maxnum,a[i]); ; ; ;i…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5727 Problem DescriptionSJX has 2*N magic gems. N of them have Yin energy inside while others have Yang energy. SJX wants to make a necklace with these magic gems for his beloved BHB. To avoid maki…
Necklace SJX has 2*N magic gems. N of them have Yin energy inside while others have Yang energy. SJX wants to make a necklace with these magic gems for his beloved BHB. To avoid making the necklace too Yin or too Yang, he must place these magic gems…
好久没写过博客了,把以前的博客补一下. Necklace Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3603    Accepted Submission(s): 1097 Problem Description SJX has 2*N magic gems. N of them have Yin energy inside whi…
Necklace Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2462    Accepted Submission(s): 775 Problem Description SJX has 2*N magic gems. N of them have Yin energy inside while others have Yang e…
A. Best Subsegment 显然,选择数列中的最大值当做区间(长度为\(1\)).只要尝试最大值这个区间是否能扩展(左右两边值是否跟它一样就行了) #include <cstdio> #include <iostream> #include <cmath> using namespace std; const int N = 100010; int n, a[N], val = -1, res = -1; int main(){ scanf("%d&…
time limit per test 2 second memory limit per test 256 megabytes input standard inputoutput standard output You a captain of a ship. Initially you are standing in a point (x1,y1)(x1,y1) (obviously, all positions in the sea can be described by cartesi…
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4102743.html 题目链接:hdu 4778 Gems Fight! 博弈+状态dp+搜索 不难发现,无论Alice和Bob以何种方式投掷包裹,他们得到的Magic Stones个数的和$Sum$是一定的,因此只需要计算Alice可以获得的最大的Magic Stones的个数MAXA,则Bob获得的个数为Sum-MAXA,而两者的最大的差为MAXA-(sum-MAXA)为答案.那么如何…
Gems Fight! Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)Total Submission(s): 1069    Accepted Submission(s): 456 Problem Description Alice and Bob are playing "Gems Fight!": There are Gems of G differen…
本系列主要参考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同时会加上一点个人理解或拓展. 这里是本书所有的插图.这里是本书所需的代码和资源(当然你也可以从官网下载). ========================================== 分割线 ========================================== 写在前面 啦啦啦~我又回来看书啦.文章开始说一些题外话.因为写博客和在群里比较活跃(为什么QQ给我的…
Gems Fight! Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)Total Submission(s): 114    Accepted Submission(s): 46 Problem Description Alice and Bob are playing "Gems Fight!": There are Gems of G different…
转自:http://blog.csdn.net/candycat1992/article/details/38147767 本系列主要参考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同时会加上一点个人理解或拓展. 这里是本书所有的插图.这里是本书所需的代码和资源(当然你也可以从官网下载). ========================================== 分割线 ===============================…
链接:https://ac.nowcoder.com/acm/contest/3570/H 来源:牛客网 题目描述 There was a magic necklace. The necklace is made of magical gems numbered 1 through n. Unfortunately, the necklace was accidentally broken yesterday. Every gem was scattered on the ground. Now…
Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others) Total Submission(s): 1912    Accepted Submission(s): 824 Problem Description Alice and Bob are playing "Gems Fight!": There are Gems of G different colors ,…
安装cocoapods,记录两个问题! 1.镜像已经替换成了 http://ruby.taobao.org/, 还是不能不能安装cocoapods, 报错:Unable to download data from http://ruby.taobao.org/ - bad response Not Found 404 (http://ruby.taobao.org/latest_specs.4.8.gz) 如图: 原来是ruby.taobao.org已经停止基于 HTTP 协议的镜像服务, 启用…
D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of…
A magic index in an array A[0...n-1] is defined to be an index such that A[i] = i. Given a sorted array of distinct integers, write a method to find a magic index, if one exists, in array A. FOLLOW UP What if the values are not distinct? public int g…