Codeforces Round #196 (Div. 2)(c快速幂)
来源:互联网 发布:西安交通大学网络 编辑:程序博客网 时间:2024/04/30 08:50
A - Puzzles
#include<iostream>#include<algorithm>using namespace std;const int maxn=60;const int INF=1000000000;int n,m,a[maxn],sum[maxn];int main(){ cin>>n>>m; for(int i=1;i<=m;i++) cin>>a[i]; sort(a+1,a+m+1); int min1=INF; for(int i=1;i<=m-n+1;i++) min1=min(min1,a[i+n-1]-a[i]); cout<<min1<<endl; return 0;}
B - Routine Problem
刚开始没太看明白题意,改了好半天,
只可能出现两种情况。即先把图像的长变为和框架的长一样或把图像的高变为和框架的高一样。两种情况比例分别为
(b*c-a*d)/(b*c)和(a*d-b*c)/(a*d)。因为b*c-a*d和a*d-b*c互为相反数所以取正的那个就行了。只是要注意答案要约分。还有分子为0的情况。分母必须为1。所以要特殊处理。
#include<cstdio>int gcd(int a, int b){ return b > 0 ? gcd(b, a % b) : a;}int main(void){ int a, b, c, d, temp; scanf("%d%d%d%d", &a, &b, &c, &d); if (b * c - a * d > 0) { int p = b * c - a * d, q = b * c; temp = gcd(p, q); printf("%d/%d", p / temp, q / temp); } else if (a * d - b * c > 0) { int p = a * d - b * c, q = a * d; temp = gcd(p, q); printf("%d/%d", p / temp, q / temp); } else printf("0/1"); return 0;}
C - Quiz
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const long long MOD=1000000009LL;long long n,m,k;long long Pow(long long a,long long n){ long long res=1; while(n>0) { if(n&1)res=res*a%MOD; a=a*a%MOD; n>>=1; } return res;}int main(){ cin>>n>>m>>k; long long sum=(k-1)*(n/k)+n%k; if(sum>=m){cout<<m%MOD<<endl;return 0;} long long b=m-sum; sum-=b*(k-1); long long an=4*k%MOD*Pow(2,b-1)%MOD; an%=MOD; an-=2*k; an=(an+MOD)%MOD; sum+=an; sum=(sum+MOD)%MOD; sum%=MOD; cout<<sum<<endl; return 0;}
0 0
- Codeforces Round #196 (Div. 2)(c快速幂)
- Codeforces Round #196 (Div. 2) C--Quiz(快速幂+贪心)
- Codeforces Round #196 (Div. 2) C. Quiz
- Codeforces Round #196 (Div. 2) C. Quiz
- Codeforces Round #196 (Div. 2) / 337C Quiz (贪心&快速幂取模)
- Codeforces Round #191 (Div. 2) C. Magic Five 等比数列的快速幂
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #226 (Div. 2) E(矩阵快速幂)
- Codeforces Round #196 (Div. 2)
- Codeforces Round #196 (Div. 2)
- Codeforces Round #196 (Div. 2)
- Codeforces Round #196 (Div. 2)
- Codeforces Round #196 (Div. 2)
- Codeforces Round #196 (Div. 2)
- Codeforces Round #196 (Div. 2) A,B,C
- Codeforces Round #118 (Div. 2) :C (矩阵快速幂)类似与斐波那契+矩阵乘法
- Codeforces Round #105 (Div. 2) C
- Codeforces Round 134 div 2 C题
- 计算机相关书籍推荐(CSDN)
- 如何计算一个整形数组里的连续元素和的最大值?
- 二叉树的创建及中序遍历
- 限售股解禁对股价的影响
- ios学习笔记——ios内的控件自定义(appearance)
- Codeforces Round #196 (Div. 2)(c快速幂)
- UNetbootin
- C语言简单编程
- JPA主要操作方法总结
- WordReverse
- 在EditText中弹出数字键盘输入密码
- nyoj-815-三角形
- 关于Windows安全权限的学习
- gsu 2524 Frozen Rose-Heads