Codeforces Round #395 (Div. 2) - A
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #395 (Div. 2) - A
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
?
題目鏈接:http://codeforces.com/contest/764/problem/A
題意:有兩個人,第一個人每n分鐘到達一次目的地,第二個人每m分鐘到達一次目的地,現在給定一個時間z問在z這個時間范圍內兩人相遇的次數。
思路:由于z,n,m的范圍比較小。所以直接開個數組暴力模擬就好了。 ?更簡單的其實答案就是z/lcm(n,m)
#define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<stdio.h> #include<queue> #include<vector> #include<stack> #include<map> #include<set> #include<time.h> #include<cmath> using namespace std; #define x first #define y second #define pb push_back #define mp make_pair typedef long long int LL; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3fLL; const int MAXN = 1e4 + 10; int v[MAXN]; int main(){ //#ifdef kirito // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); //#endif // int start = clock();int n,m,z;while (~scanf("%d%d%d", &n,&m,&z)){memset(v, 0, sizeof(v));for (int i = 1; i*n <= z; i++){v[i*n]++;}int ans = 0;for (int i = 1; i*m <= z; i++){if (v[i*m] > 0){ans++;}}printf("%d\n", ans);} //#ifdef LOCAL_TIME // cout << "[Finished in " << clock() - start << " ms]" << endl; //#endifreturn 0; }?
#define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<stdio.h> #include<queue> #include<vector> #include<stack> #include<map> #include<set> #include<time.h> #include<cmath> using namespace std; #define x first #define y second #define pb push_back #define mp make_pair typedef long long int LL; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3fLL; const int MAXN = 1e5 + 10; int gcd(int x, int y){return y==0? x : gcd(y, x%y); } int lcm(int x, int y){return x*y / gcd(x, y); } int main(){ //#ifdef kirito // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); //#endif // int start = clock();int n,m,z;while (~scanf("%d%d%d", &n,&m,&z)){printf("%d\n", z / lcm(n, m));} //#ifdef LOCAL_TIME // cout << "[Finished in " << clock() - start << " ms]" << endl; //#endifreturn 0; }?
轉載于:https://www.cnblogs.com/kirito520/p/6363481.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的Codeforces Round #395 (Div. 2) - A的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 天气小偷程序
- 下一篇: Binary Tree Maximum