Codeforces Educational Codeforces Round 16 部分题解
来源:互联网 发布:ps淘宝图标教程视频 编辑:程序博客网 时间:2024/05/19 13:30
ECR场的题一般都比较水,而我这种菜鸡就只能写写这样的题解来安慰一下自己了。
传送门:http://codeforces.com/contest/710
A、B、C都是语言入门题,就不说了。贴上C找规律的代码:
#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<math.h>using namespace std;int a[50][50];int main (){ int n; scanf("%d",&n); int p=2,q=1,x=(n+1)/2; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(abs(j-x)>=x-abs(x-i)) { printf("%d ",p); p+=2; }else{ printf("%d ",q); q+=2; } } printf("\n"); } return 0;}
代码丑,勿喷。
此题废了不少时间,起初暴力TLE,然后写了个类似扩展欧几里得算法A了,既然说类似,当然就不是,思路是解出方程:ka1+b1=la2+b2 中 k (或 l)的一个非负整数解,得出一个 x 值 ,然后…然后就出结果了
AC代码:
#include<iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<algorithm>#define LL long longusing namespace std;LL l,r,a1,b1,a2,b2,g,ans;LL gcd(LL x,LL y) { return x ? gcd(y%x,x) : y;}LL exgcd(LL a,LL b,LL c) { return a ? (exgcd(b%a,a,-c)*b+c)/a : c/b;}int main() { cin>>a1>>b1>>a2>>b2>>l>>r; l=max(l,b1); l=max(l,b2); g=gcd(a1,a2); if(abs(b1-b2)%g!=0) { printf("0"); return 0; } if(b1<b2) swap(b1,b2),swap(a1,a2); LL k=exgcd(a1,a2,b2-b1); k=k%(a2/g); LL b=b1+k*a1,a=1LL*a1*a2/gcd(a1,a2); if(b>r) ans=0; else if(b<l) ans=(r-b)/a-(l-1-b)/a; else ans=(r-b)/a+1; cout<<ans; return 0;}
E题,DP看代码:
#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>using namespace std;long long dp[10000001];int main () { long long n,x,y; scanf("%I64d%I64d%I64d",&n,&x,&y); dp[0]=0; for(long long i=1; i<=n; i++) { dp[i]=dp[i-1]+x; if(i%2==0) { dp[i]=min(dp[i/2]+y,dp[i]); dp[i]=min(dp[i/2+1]+x+y,dp[i]); dp[i]=min(dp[i/2-1]+x+y,dp[i]); }else{ dp[i]=min(dp[i],dp[(i+1)/2]+y+x); } } printf("%I64d\n",dp[n]); return 0;}
好像状态转移有重复,但不影响AC,懒得改了。
1 0
- Codeforces Educational Codeforces Round 16 部分题解
- Educational Codeforces Round 7 题解
- Educational Codeforces Round 7 题解
- Educational Codeforces Round 14 题解
- Educational Codeforces Round 20题解
- Educational Codeforces Round 24 题解
- Educational Codeforces Round 23 题解
- Educational Codeforces Round 22 题解
- Educational Codeforces Round 25 题解
- Educational Codeforces Round 21 题解
- Educational Codeforces Round 29 题解
- Educational Codeforces Round 19 题解
- Educational Codeforces Round 28 题解
- Educational Codeforces Round 31 题解
- Educational Codeforces Round 32[题解]
- Educational Codeforces Round 30 题解
- Educational Codeforces Round 32 题解
- Educational Codeforces Round 17 题解
- 合伙人制度是梦想、价值观和利益的捆绑
- 前端-调试工具
- Bootstrap Table使用心得总结
- ElasticSearch Index templates属性描述
- JavaWeb项目乱码问题解决方法
- Codeforces Educational Codeforces Round 16 部分题解
- ubuntu下折腾ReactNative
- redis的数据结构
- Eclipse工程目录下建立bat文件运行Java程序
- ARM cortex a 的SDRAM (DDR)
- Impinj Spedway 在使用 Telnet 时需要用 Putty 进行连接,并且连接类型需要选 SSH
- iqiyi Thrift服务框架整体介绍
- JavaScript DOM基础知识总结
- 从零学React Native之10Text