hdu 4768 Flyer 二分
生活随笔
收集整理的這篇文章主要介紹了
hdu 4768 Flyer 二分
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
http://acm.hdu.edu.cn/showproblem.php?pid=4768
思路:
解題關(guān)鍵是奇數(shù)+偶數(shù)=奇數(shù),然后我們就是枚舉奇數(shù)位置(奇數(shù)為就一個或者0個),然后計算左邊的和是否為奇數(shù),如果是奇數(shù),那么該點就存在與左邊,否則存在于右邊
?
#include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <algorithm> #include <string> #include <set> #include <functional> #include <numeric> #include <sstream> #include <stack> #include <map> #include <time.h> #include <queue>#define CL(arr, val) memset(arr, val, sizeof(arr))#define lc l,m,rt<<1 #define rc m + 1,r,rt<<1|1 #define pi acos(-1.0) #define ll long long #define L(x) (x) << 1 #define R(x) (x) << 1 | 1 #define MID(l, r) (l + r) >> 1 #define Min(x, y) (x) < (y) ? (x) : (y) #define Max(x, y) (x) < (y) ? (y) : (x) #define E(x) (1 << (x)) #define iabs(x) (x) < 0 ? -(x) : (x) #define OUT(x) printf("%I64d\n", x) #define keyTree (chd[chd[root][1]][0]) #define Read() freopen("din.txt", "r", stdin) #define Write() freopen("dout.txt", "w", stdout); #define random(x) (rand()%x)#define M 100007 #define N 20007using namespace std;int dx[4]={-1,1,0,0}; int dy[4]={0,0,-1,1};const int inf = 0x7f7f7f7f; const int mod = 1000000007;const double eps = 1e-8; const int R = 100007;int A[N],B[N],C[N]; int n;ll solve(int mid) {ll sum = 0;int limt;for (int i = 0; i < n; ++i){if(mid < A[i]) continue;limt = min(mid, B[i]);if (C[i] == 0) sum += 1;else{sum += (limt - A[i])/C[i] + 1;}}return sum; } int main() {while (~scanf("%d",&n)){int top = 0;for (int i = 0; i < n; ++i){cin>>A[i]>>B[i]>>C[i];top = max(top,B[i]);}int l = 1, r = top;int ans = 0;while (l <= r){int mid = ((ll)l + (ll)r)>>1;ll sum = solve(mid);if ((sum & 1) == 1){ans = mid;r = mid - 1;} else {l = mid + 1;}}if (ans == 0) printf("DC Qiang is unhappy.\n");else{int cnt = 0;for (int i = 0; i < n; ++i){if (ans <= B[i]){if (C[i] == 0){if (ans == A[i]) cnt++;} else {if (ans >= A[i] && (ans - A[i])%C[i] == 0) cnt++;}}}printf("%d %d\n",ans,cnt);}}return 0; }
轉(zhuǎn)載于:https://www.cnblogs.com/E-star/p/3346928.html
總結(jié)
以上是生活随笔為你收集整理的hdu 4768 Flyer 二分的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 判断脚本,图片,CSS,iframe等是
- 下一篇: 中西三大差距根源在哪里?