本文主要是介绍Codeforces---125--div2--总结,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
A题:
http://codeforces.com/contest/199/problem/A
因为0也属于fibonacci数列,所以直接输出0, 0, n;
另外也可以用递推的方法,代码:
/*
收获:
*/
#include<iostream>
#include<cstdlib>
#include<vector>
#include<map>
#include<cstring>
#include<set>
#include<string>
#include<algorithm>
#include<sstream>
#include<ctype.h>
#include<fstream>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<stack>
#include<queue>
#include<ctime>
//#include<conio.h>
using namespace std;const int INF_MAX=0x7FFFFFFF;
const int INF_MIN=-(1<<31);const double eps=1e-10;
const double pi=acos(-1.0);#define pb push_back //a.pb( )
#define chmin(a,b) ((a)<(b)?(a):(b))
#define chmax(a,b) ((a)>(b)?(a):(b))template<class T> inline T gcd(T a,T b)//NOTES:gcd({if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<class T> inline T lcm(T a,T b)//NOTES:lcm({if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
int dir_4[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
int dir_8[8][2]={{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1}};
//下,左下,左,左上,上,右上,右,右下。//******* WATER ****************************************************************long long find(long long k)
{long long a = 0;long long b = 1;long long c = 1;while(c != k){a = b;b = c;c = a + b;}return b;
}int main()
{//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);long long k;cin>>k;if(k == 0) cout<<"0 0 0"<<endl;else if(k == 1) cout<<"0 0 1"<<endl;else{long long kk = find(k);cout<<2 * k - 3 * kk<<" "<<2 * kk - k<<" "<<kk<<endl;}return 0;//printf("%.6f\n",(double)clock()/CLOCKS_PER_SEC);
}
http://codeforces.com/contest/199/problem/B
需要讨论一个圆和一个环的几种关系:
1.圆在圆环内部。
情况1
情况2
2. 圆在圆环外部
情况1
情况2
其他的情况均是有相交的不完整的情况。
只要对四个圆和两个圆环分别代入写的子函数中返回是否相交,就可以得出答案。
小技巧:比较中含有根号的时候可以同时平方来比较。
code:
/*
收获:
*/
#include<iostream>
#include<cstdlib>
#include<vector>
#include<map>
#include<cstring>
#include<set>
#include<string>
#include<algorithm>
#include<sstream>
#include<ctype.h>
#include<fstream>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<stack>
#include<queue>
#include<ctime>
//#include<conio.h>
using namespace std;const int INF_MAX=0x7FFFFFFF;
const int INF_MIN=-(1<<31);const double eps=1e-10;
const double pi=acos(-1.0);#define pb push_back //a.pb( )
#define chmin(a,b) ((a)<(b)?(a):(b))
#define chmax(a,b) ((a)>(b)?(a):(b))template<class T> inline T gcd(T a,T b)//NOTES:gcd({if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<class T> inline T lcm(T a,T b)//NOTES:lcm({if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
int dir_4[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
int dir_8[8][2]={{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1}};
//下,左下,左,左上,上,右上,右,右下。//******* WATER ****************************************************************typedef struct
{int x, y;int r;
}circle;int judge_intersecotiono(circle a, circle b)
{double dis = sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) );if(fabs(dis - abs(a.r + b.r)) < eps) return 2;else if(fabs(dis - abs(a.r - b.r)) < eps) return 3;else if( dis > abs(a.r - b.r) && dis < abs(a.r + b.r)) return 1;//相交else if(dis > abs(a.r + b.r) ) return 2;//相离else return 3;//内含
}int judge_in(circle a, circle b, circle c)
{if(judge_intersecotiono(a, b) == 2 && judge_intersecotiono(a, c) == 3) return 1;//被覆盖else return 0;//未覆盖
}int judge_cover(circle a, circle b, circle c)
{double dis1 = sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) );double dis2 = sqrt( (a.x - c.x) * (a.x - c.x) + (a.y - c.y) * (a.y - c.y) );if(b.r < a.r && dis1 < fabs(a.r - b.r) + eps && c.r > a.r && dis2 < fabs(a.r - c.r) + eps) return false;else return true;
}bool judge_ok(circle a, circle b, circle c)
{if(judge_in(a, b, c) == 0 && judge_intersecotiono(a, b) != 1 && judge_intersecotiono(a, c) != 1 && judge_cover(a, b, c)) return true;else return false;
}int main()
{//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);circle a1, a2;circle b1, b2;int a, b, c, d;cin>>a>>b>>c>>d;a1.x = a2.x = a;a1.y = a2.y = b;a1.r = c;a2.r = d;cin>>a>>b>>c>>d;b1.x = b2.x = a;b1.y = b2.y = b;b1.r = c;b2.r = d;int ans = 0;if(judge_ok(a1, b1, b2)) ans++;if(judge_ok(a2, b1, b2)) ans++;if(judge_ok(b1, a1, a2)) ans++;if(judge_ok(b2, a1, a2)) ans++;cout<<ans<<endl;//printf("%.6f\n",(double)clock()/CLOCKS_PER_SEC);
}
C题:
http://codeforces.com/contest/199/problem/C
考虑 第一种情况经历s时间后第一次超过了t,那么从这个时候开始就可以了。
trick:要用long long ,因为有乘法运算会超出int界。
/*
收获:
*/
#include<iostream>
#include<cstdlib>
#include<vector>
#include<map>
#include<cstring>
#include<set>
#include<string>
#include<algorithm>
#include<sstream>
#include<ctype.h>
#include<fstream>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<stack>
#include<queue>
#include<ctime>
//#include<conio.h>
using namespace std;const int INF_MAX=0x7FFFFFFF;
const int INF_MIN=-(1<<31);const double eps=1e-10;
const double pi=acos(-1.0);#define pb push_back //a.pb( )
#define chmin(a,b) ((a)<(b)?(a):(b))
#define chmax(a,b) ((a)>(b)?(a):(b))template<class T> inline T gcd(T a,T b)//NOTES:gcd({if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<class T> inline T lcm(T a,T b)//NOTES:lcm({if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
int dir_4[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
int dir_8[8][2]={{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1}};
//下,左下,左,左上,上,右上,右,右下。//******* WATER ****************************************************************LL timee(LL k, LL b, LL n, LL t)
{LL ret = 0;LL now = 1;while(now <= t){now = now * k + b;ret++;}return ret - 1;
}int main()
{//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);LL k, b, n, t;cin>>k>>b>>n>>t;if(n >= timee(k, b, n, t)) cout<<n - timee(k, b, n, t)<<endl;else cout<<0<<endl;//printf("%.6f\n",(double)clock()/CLOCKS_PER_SEC);
}
D题:
http://codeforces.com/contest/199/problem/D
这个题目需要用BFS来做,当时我用的是DFS,是不对的,因为DFS会搜索很多重复的边,而且很多边不能记录对它最早的搜索,导致了TLE。
code由于是看别人的,在此不粘贴了。
E题:
http://codeforces.com/contest/199/problem/E
需要用二分的方法,求得不过圆的最近距离,分两种情况:
1. AB线段不过圆。
2. AB线段过圆,这时候沿着圆走,具体开始地点进行二分。
code未写,方法如上。
这篇关于Codeforces---125--div2--总结的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!