日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Showstopper [POJ3484] [二分] [思维]

發布時間:2023/11/27 生活经验 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Showstopper [POJ3484] [二分] [思维] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Description

給你n個數列,問哪一個數字在所有的數列中出現了奇數次(最多一個)。

?

Sample Input

1 10 1
2 10 11 10 1
1 10 11 10 1
4 4 1
1 5 1
6 10 1

Sample Output

1 1
no corruption
4 3

?

Analysis

我們假裝按大小排好了每個數,然后我們發現,如果統計每個數出現的次數,要求的數X是奇數,其他的是偶數,那么記錄前綴和,X之前全為偶數(偶+偶+...+偶=偶),X及X以后都是奇數(奇+偶=奇),那我們就可以按照這個規律二分了。

這道題還是蠻有意思的,如果奇數和偶數對掉的話,這道題就不可做了。

?

Code?

 1 #include<set>
 2 #include<map>
 3 #include<queue>
 4 #include<stack>
 5 #include<cmath>
 6 #include<cstdio>
 7 #include<cstring>
 8 #include<iostream>
 9 #include<algorithm>
10 #define RG register int
11 #define rep(i,a,b)    for(RG i=a;i<=b;++i)
12 #define per(i,a,b)    for(RG i=a;i>=b;--i)
13 #define ll long long
14 #define inf 0x8f8f8f8f8f
15 #define maxn 100005
16 using namespace std;
17 ll X[maxn],Y[maxn],Z[maxn],cnt;
18 char s[maxn];
19 inline int read()
20 {
21     int x=0,f=1;char c=getchar();
22     while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
23     while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
24     return x*f;
25 }
26 
27 int judge(ll lim)
28 {
29     ll sum=0;
30     rep(i,1,cnt)
31     {
32         if(lim<X[i])    continue;
33         sum+=(min(Y[i],lim)-X[i])/Z[i]+1;
34     }
35     return sum&1;
36 }
37 
38 ll cal(ll lim)
39 {
40     ll sum=0;
41     rep(i,1,cnt)
42     {
43         if(lim<X[i])    continue;
44         sum+=(min(Y[i],lim)-X[i])/Z[i]+1;
45     }
46     return sum;
47 }
48 
49 void work()
50 {
51     ll l=1,r=inf,mid,ans=-1;
52     while(l<=r)
53     {
54         mid=(l+r)>>1;
55         if(judge(mid))    ans=mid,r=mid-1;
56         else            l=mid+1;
57     }
58     if(ans==-1)    puts("no corruption");
59     else
60     {
61         printf("%lld %lld\n",ans,cal(ans)-cal(ans-1));
62     }
63 }
64 
65 int main()
66 {
67     while(gets(s)!=NULL)
68     {
69         if(!strlen(s))
70         {
71             if(!cnt)    continue;
72             work();cnt=0;
73         }
74         else
75         {
76             ++cnt;
77             sscanf(s,"%lld %lld %lld",&X[cnt],&Y[cnt],&Z[cnt]);
78         }
79     }
80     if(cnt) work();
81     return 0;
82 }
View Code

?

轉載于:https://www.cnblogs.com/ibilllee/p/9285966.html

總結

以上是生活随笔為你收集整理的Showstopper [POJ3484] [二分] [思维]的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。