如果沒有導出公式
1 1000000000 就會Timeout了
種樹問題
oo1oo1oo
每兩棵蘋果樹間要種一棵橘子樹
要種n顆蘋果樹的話,一共種了幾棵樹?
function的使用
數列的推導
2013年12月21日 星期六
ProblemD-跑者的修煉 (Timeout)
#include <iostream> using namespace std; long long f( long long m,long long x){ return x+(x-1)/m; } long long g( long long m,long long x){ long long s=0; for (long long i=1;i<=x;i++) s+=f(m,i); return s; } int main(){ int T; long long m,n; cin >> T; while(T>0){ cin >>m>> n; cout << g(m,n) << endl; T--; } return 0; }
2013年12月20日 星期五
ProblemD-跑者的修煉
#include <iostream> using namespace std; int f( int m,int x){ return x+(x-1)/m; } int g( int m,int x){ int s=0; for (int i=1;i<=x;i++) s+=f(m,i); return s; } int main(){ int m,n; cin >>m>> n; cout << g(m,n) << endl; system("pause"); return 0; }
ProblemD-跑者的修煉
#include <iostream> using namespace std; int f(int x){ return x+(x-1)/5; } int g(int x){ int s=0; for (int i=1;i<=x;i++) s+=f(i); return s; } int main(){ int n; cin >> n; cout << g(n) << endl; system("pause"); return 0; }
2013年12月14日 星期六
求三個數中最大 ==> 求六個數中最大值 ==> 求六個數中第三大的
#include <iostream> #include <algorithm> using namespace std; int main(){ int cases; int a[6]; cin >> cases; while(cases--){ for (int i=0;i<6;i++) cin >> a[i]; cout << *max_element(a,a+6) << endl; } }
訂閱:
意見 (Atom)