标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1718 Accepted Submission(s): 622
12940329 | 2015-02-12 17:35:01 | Accepted | 4768 | 78MS | 1756K | 1933 B | G++ | czy |
1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<algorithm> 6 #include<cmath> 7 #include<queue> 8 #include<map> 9 #include<set> 10 #include<stack> 11 #include<string> 12 13 #define N 20005 14 #define M 205 15 #define mod 10000007 16 //#define p 10000007 17 #define mod2 1000000000 18 #define ll long long 19 #define LL long long 20 #define eps 1e-6 21 #define inf 100000000 22 #define maxi(a,b) (a)>(b)? (a) : (b) 23 #define mini(a,b) (a)<(b)? (a) : (b) 24 25 using namespace std; 26 27 int n; 28 ll a[N],b[N],c[N]; 29 ll num[N]; 30 ll ans; 31 ll ma; 32 ll cc; 33 34 void ini() 35 { 36 int i; 37 ma=0; 38 for(i=1;i<=n;i++){ 39 scanf("%I64d%I64d%I64d",&a[i],&b[i],&c[i]); 40 ma=max(ma,b[i]); 41 num[i]=(b[i]-a[i])/c[i]+1; 42 } 43 } 44 45 ll ok(ll l,ll r) 46 { 47 int i; 48 ll re; 49 re=0; 50 ll t1,t2; 51 l--; 52 for(i=1;i<=n;i++){ 53 if(l>b[i] || r<a[i]) continue; 54 if(l<a[i]){ 55 t1=0; 56 } 57 else{ 58 t1=(l-a[i])/c[i]+1; 59 } 60 if(r>b[i]){ 61 t2=num[i]; 62 } 63 else{ 64 t2=(r-a[i])/c[i]+1; 65 } 66 re+=t2-t1; 67 } 68 if(re%2==1) return re; 69 else return 0; 70 } 71 72 void solve() 73 { 74 ll l,r,mid; 75 l=0;r=ma; 76 while(l<r) 77 { 78 mid=(l+r)/2; 79 cc=ok(l,mid); 80 if(cc!=0) 81 { 82 r=mid; 83 } 84 else{ 85 l=mid+1; 86 } 87 } 88 ans=l; 89 cc=ok(l,l); 90 } 91 92 void out() 93 { 94 if(cc==0){ 95 printf("DC Qiang is unhappy.\n"); 96 } 97 else 98 printf("%I64d %I64d\n",ans,cc); 99 } 100 101 int main() 102 { 103 //freopen("data.in","r",stdin); 104 //freopen("data.out","w",stdout); 105 //scanf("%d",&T); 106 //for(int ccnt=1;ccnt<=T;ccnt++) 107 //while(T--) 108 //scanf("%d%d",&n,&m); 109 while(scanf("%d",&n)!=EOF) 110 { 111 if(n==0) break; 112 ini(); 113 solve(); 114 out(); 115 } 116 return 0; 117 }
标签:
原文地址:http://www.cnblogs.com/njczy2010/p/4288612.html