http://acm.hdu.edu.cn/showproblem.php?pid=4768
思路:
解题关键是奇数+偶数=奇数,然后我们就是枚举奇数位置(奇数为就一个或者0个),然后计算左边的和是否为奇数,如果是奇数,那么该点就存在与左边,否则存在于右边
#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 ", 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 20007 using 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. "); 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 ",ans,cnt); } } return 0; }