锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久久噜噜噜亚洲熟女综合
,欧美久久久久久,久久福利青草精品资源站免费 http://www.shnenglu.com/Darren/category/12421.htmlC++ 鍙婄畻娉?/description>zh-cn Fri, 27 Nov 2009 14:00:58 GMT Fri, 27 Nov 2009 14:00:58 GMT 60 HDU 1255 http://www.shnenglu.com/Darren/archive/2009/08/06/92384.htmlDarren Darren Thu, 06 Aug 2009 01:59:00 GMT http://www.shnenglu.com/Darren/archive/2009/08/06/92384.html http://www.shnenglu.com/Darren/comments/92384.html http://www.shnenglu.com/Darren/archive/2009/08/06/92384.html#Feedback 0 http://www.shnenglu.com/Darren/comments/commentRss/92384.html http://www.shnenglu.com/Darren/services/trackbacks/92384.html
#include聽
<
iostream
>
#include聽
<
algorithm
>
using
聽
namespace
聽std;
#define
聽N聽2110
struct
聽Tree
{ 聽聽聽聽
double
聽length,聽len; 聽聽聽聽
int
聽聽聽聽cnt; 聽聽聽聽Tree()
{聽length
=
聽
0
;聽cnt
=
聽
0
;聽}
聽聽聽聽
void
聽init()
{聽length
=
聽
0
;聽cnt
=
聽
0
;聽len
=
聽
0
;聽}
}
tb[
10100
];
double
聽x1[N],聽y1[N],聽x2[N],聽y2[N],聽xx[N],聽idx[N];
int
聽pos,聽n;
struct
聽Line
{ 聽聽聽聽
double
聽y,聽x1,聽x2; 聽聽聽聽
bool
聽type; }
line[N];
bool
聽
operator
<
(聽Line聽
const
&
聽a,聽Line聽
const
&
聽b聽)
{ 聽聽聽聽
return
聽a.y
<
聽b.y;聽}
聽聽聽聽 inline聽
int
聽bsearch(聽
double
聽value聽)
{ 聽聽聽聽
int
聽low
=
聽
1
,聽high
=
聽pos
+
聽
1
; 聽聽聽聽
while
(聽low
<=
聽high聽)
{ 聽聽聽聽聽聽聽聽
int
聽mid
=
聽(low
+
聽high)
>>
聽
1
; 聽聽聽聽聽聽聽聽
if
(聽idx[mid]
>
聽value聽)聽high
=
聽mid
-
聽
1
; 聽聽聽聽聽聽聽聽
else
聽
if
(聽idx[mid]
<
聽value聽)聽low
=
聽mid
+
聽
1
; 聽聽聽聽聽聽聽聽
else
聽
return
聽mid;聽}
}
inline聽
void
聽update(聽
int
聽rt,聽
int
聽l,聽
int
聽r聽)
{ 聽聽聽聽
if
(聽tb[rt].cnt聽)聽tb[rt].length
=
聽idx[r]
-
聽idx[l]; 聽聽聽聽
else
聽
if
(聽l
+
聽
1
==
聽r聽)聽tb[rt].length
=
聽
0
; 聽聽聽聽
else
聽tb[rt].length
=
聽tb[rt
<<
1
].length
+
聽tb[(rt
<<
1
)
+
1
].length; }
inline聽
void
聽update2(聽
int
聽rt,聽
int
聽l,聽
int
聽r聽)
{ 聽聽聽聽
if
(聽tb[rt].cnt
>
聽
1
聽)聽tb[rt].len
=
聽idx[r]
-
聽idx[l]; 聽聽聽聽
else
聽
if
(聽tb[rt].cnt
==
聽
1
聽)聽tb[rt].len
=
聽tb[rt
<<
1
].length
+
聽tb[(rt
<<
1
)
+
1
].length; 聽聽聽聽
else
聽tb[rt].len
=
聽tb[rt
<<
1
].len
+
聽tb[(rt
<<
1
)
+
1
].len;聽}
void
聽deal(聽
int
聽rt,聽
int
聽l,聽
int
聽r,聽
int
聽a,聽
int
聽b,聽
int
聽t聽)
{ 聽聽聽聽
if
(聽a
<=
聽l聽
&&
聽b
>=
聽r聽)
{ 聽聽聽聽聽聽聽聽tb[rt].cnt
+=
聽t;聽update(聽rt,聽l,聽r聽);聽update2(聽rt,聽l,聽r聽);聽聽
return
;聽}
聽聽聽聽聽聽聽聽 聽聽聽聽
int
聽mid
=
聽(l
+
聽r)
>>
聽
1
; 聽聽聽聽
if
(聽a
<
聽mid聽)聽deal(聽rt
<<
聽
1
,聽l,聽mid,聽a,聽b,聽t); 聽聽聽聽
if
(聽b
>
聽mid聽)聽deal(聽(rt
<<
1
)
+
聽
1
,聽mid,聽r,聽a,聽b,聽t聽); 聽聽聽聽 聽聽聽聽update(聽rt,聽l,聽r聽);聽update2(聽rt,聽l,聽r聽); }
int
聽main()
{ 聽聽聽聽
int
聽test
=
聽
1
; 聽聽聽聽scanf(
"
%d
"
,
&
test聽); 聽聽聽聽
while
(聽test
--
聽)
{ 聽聽聽聽聽聽聽聽scanf(
"
%d
"
,
&
n); 聽聽聽聽聽聽聽聽
for
(聽
int
聽i
=
聽
0
;聽i
<=
聽
10000
;聽
++
i聽)聽tb[i].init(); 聽聽聽聽聽聽聽聽
for
(聽
int
聽i
=
聽
0
;聽i
<
聽n;聽
++
i聽)聽
{ 聽聽聽聽聽聽聽聽聽聽聽聽scanf(
"
%lf%lf%lf%lf
"
,聽x1
+
聽i,聽y1
+
聽i,聽x2
+
聽i,聽y2
+
聽i聽); 聽聽聽聽聽聽聽聽聽聽聽聽line[
2
*
i].y
=
聽y1[i];聽聽聽line[
2
*
i].x1
=
聽x1[i];聽 聽聽聽聽聽聽聽聽聽聽聽聽line[
2
*
i].x2
=
聽x2[i];聽聽line[
2
*
i].type
=
聽
0
; 聽聽聽聽聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽聽聽聽聽xx[
2
*
i]
=
聽x1[i];聽xx[
2
*
i
+
聽
1
]
=
聽x2[i]; 聽聽聽聽聽聽聽聽聽聽聽聽line[
2
*
i
+
1
].y
=
聽y2[i];聽聽line[
2
*
i
+
1
].x1
=
聽x1[i]; 聽聽聽聽聽聽聽聽聽聽聽聽line[
2
*
i
+
1
].x2
=
聽x2[i];聽line[
2
*
i
+
1
].type
=
聽
1
; 聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽sort(聽xx,聽xx
+
聽
2
*
聽n聽);聽聽聽聽sort(聽line,聽line
+
聽
2
*
聽n聽); 聽聽聽聽聽聽聽聽pos
=
聽
1
;聽idx[
1
]
=
聽xx[
0
]; 聽聽聽聽聽聽聽聽
for
(聽
int
聽i
=
聽
1
;聽i
<
聽
2
*
聽n;聽
++
i聽) 聽聽聽聽聽聽聽聽
if
(聽xx[i]
!=
聽xx[i
-
1
]聽)聽idx[
++
pos]
=
聽xx[i]; 聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽
double
聽ans
=
聽
0
; 聽聽聽聽聽聽聽聽
for
(聽
int
聽i
=
聽
0
;聽i
<
聽
2
*
聽n
-
聽
1
;聽
++
i聽)
{ 聽聽聽聽聽聽聽聽聽聽聽聽
int
聽u
=
聽bsearch(聽line[i].x1聽),聽v
=
聽bsearch(聽line[i].x2聽); 聽聽聽聽聽聽聽聽聽聽聽聽
if
(聽line[i].type
==
聽
0
聽)聽deal(聽
1
,聽
1
,聽pos,聽u,聽v,聽
1
聽); 聽聽聽聽聽聽聽聽聽聽聽聽
else
聽deal(聽
1
,聽
1
,聽pos,聽u,聽v,聽
-
1
聽); 聽聽聽聽聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽聽聽聽聽ans
+=
聽tb[
1
].len
*
聽(聽line[i
+
1
].y
-
聽line[i].y聽); 聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽printf(
"
%.2lf\n
"
,聽ans聽); 聽聽聽聽}
聽聽聽聽 聽聽聽聽
return
聽
0
; }
]]> PKU銆銆1151 http://www.shnenglu.com/Darren/archive/2009/08/06/92365.htmlDarren Darren Wed, 05 Aug 2009 16:49:00 GMT http://www.shnenglu.com/Darren/archive/2009/08/06/92365.html http://www.shnenglu.com/Darren/comments/92365.html http://www.shnenglu.com/Darren/archive/2009/08/06/92365.html#Feedback 0 http://www.shnenglu.com/Darren/comments/commentRss/92365.html http://www.shnenglu.com/Darren/services/trackbacks/92365.html 闃呰鍏ㄦ枃 ]]> ZJU 3228 Searching the String ( AC 鑷姩鏈?) http://www.shnenglu.com/Darren/archive/2009/08/02/91977.htmlDarren Darren Sun, 02 Aug 2009 14:05:00 GMT http://www.shnenglu.com/Darren/archive/2009/08/02/91977.html http://www.shnenglu.com/Darren/comments/91977.html http://www.shnenglu.com/Darren/archive/2009/08/02/91977.html#Feedback 1 http://www.shnenglu.com/Darren/comments/commentRss/91977.html http://www.shnenglu.com/Darren/services/trackbacks/91977.html 闃呰鍏ㄦ枃 ]]> Pku 1986 Distance Queries http://www.shnenglu.com/Darren/archive/2009/07/20/90590.htmlDarren Darren Mon, 20 Jul 2009 02:56:00 GMT http://www.shnenglu.com/Darren/archive/2009/07/20/90590.html http://www.shnenglu.com/Darren/comments/90590.html http://www.shnenglu.com/Darren/archive/2009/07/20/90590.html#Feedback 0 http://www.shnenglu.com/Darren/comments/commentRss/90590.html http://www.shnenglu.com/Darren/services/trackbacks/90590.html
#include聽
<
iostream
>
#include聽
<
vector
>
using
聽
namespace
聽std;
#define
聽N聽40010
typedef聽pair
<
int
,
int
>
聽PAIR;
int
聽m,聽n; vector
<
PAIR
>
聽query[N],聽map[N];
int
聽uset[N]
=
聽{
0
},聽acs[N],聽flag[N]
=
聽{
0
},聽dis[N]
=
聽{
0
},聽ans[N],聽visite[N]
=
{
0
};
int
聽find(聽
int
聽x聽){ 聽聽聽聽
while
(聽x
!=
聽uset[x]聽)聽x
=
聽uset[x]; 聽聽聽聽
return
聽x;聽}
void
聽join(聽
int
聽x,聽
int
聽y聽){聽聽uset[聽find(x)聽]
=
聽uset[聽find(y)聽];聽}
void
聽dfs(聽
int
聽u,聽
int
聽d聽){ 聽聽聽聽uset[u]
=
聽u;聽acs[u]
=
聽u;聽dis[u]
=
聽d;聽visite[u]
=
聽
1
; 聽聽聽聽
for
(聽size_t聽i
=
聽
0
;聽i
<
聽map[u].size();聽
++
i聽){ 聽聽聽聽聽聽聽聽
int
聽v
=
聽map[u][i].first,聽w
=
聽map[u][i].second; 聽聽聽聽聽聽聽聽
if
(聽
!
visite[v]聽){ 聽聽聽聽聽聽聽聽聽聽聽聽dfs(聽v,聽d
+
聽w聽); 聽聽聽聽聽聽聽聽聽聽聽聽join(聽u,聽v聽);聽acs[聽find(u)聽]
=
聽u;聽聽} 聽聽聽聽} 聽聽聽聽 聽聽聽聽flag[u]
=
聽
1
; 聽聽聽聽
for
(聽size_t聽i
=
聽
0
;聽i
<
聽query[u].size();聽
++
i聽){ 聽聽聽聽聽聽聽聽
int
聽v
=
聽query[u][i].first,聽w
=
聽query[u][i].second; 聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽
if
(聽flag[v]聽)聽ans[w]
=
聽dis[u]
+
聽dis[v]
-
聽
2
*
聽dis[聽acs[聽find(v)聽]聽]; 聽聽聽聽}聽聽聽聽 }
int
聽main(){ 聽聽聽聽
int
聽u,聽v,聽d; 聽聽聽聽
char
聽s[
10
]; 聽聽聽聽 聽聽聽聽scanf(
"
%d%d
"
,
&
n,
&
m); 聽聽聽聽
while
(聽m
--
聽){ 聽聽聽聽聽聽聽聽scanf(
"
%d%d%d%s
"
,
&
u,
&
v,
&
d,s聽); 聽聽聽聽聽聽聽聽map[u].push_back(聽PAIR(v,d)聽); 聽聽聽聽聽聽聽聽map[v].push_back(聽PAIR(u,d)聽); 聽聽聽聽} 聽聽聽聽 聽聽聽聽scanf(
"
%d
"
,
&
m聽); 聽聽聽聽
for
(聽
int
聽i
=
聽
1
;聽i
<=
聽m;聽
++
i聽){ 聽聽聽聽聽聽聽聽scanf(
"
%d%d
"
,
&
u,
&
v聽); 聽聽聽聽聽聽聽聽query[u].push_back(聽PAIR(v,i)聽); 聽聽聽聽聽聽聽聽query[v].push_back(聽PAIR(u,i)聽); 聽聽聽聽} 聽聽聽聽memset(聽flag,聽
0
,聽
sizeof
(flag)聽); 聽聽聽聽memset(聽visite,聽
0
,聽
sizeof
(visite)聽); 聽聽聽聽 聽聽聽聽dfs(聽
1
,聽
0
聽);聽 聽聽聽聽
for
(聽
int
聽i
=
聽
1
;聽i
<=
聽m;聽
++
i聽)聽printf(
"
%d\n
"
,聽ans[i]聽); 聽聽聽聽 聽聽聽聽
return
聽
0
; }
]]> Pku 3277 City Horizon http://www.shnenglu.com/Darren/archive/2009/07/15/90128.htmlDarren Darren Wed, 15 Jul 2009 04:39:00 GMT http://www.shnenglu.com/Darren/archive/2009/07/15/90128.html http://www.shnenglu.com/Darren/comments/90128.html http://www.shnenglu.com/Darren/archive/2009/07/15/90128.html#Feedback 0 http://www.shnenglu.com/Darren/comments/commentRss/90128.html http://www.shnenglu.com/Darren/services/trackbacks/90128.html
#include聽
<
iostream
>
#include聽
<
algorithm
>
#include聽
<
cstdio
>
#include聽
<
cstdlib
>
#include聽
<
cstring
>
using
聽
namespace
聽std;
#define
聽N聽40001
#define
聽max(a,b)聽(聽(a)>(b)?(a):(b)聽)
int
聽n,d[N
<<
1
],聽idx[N
<<
1
],聽pos,聽f[N
<<
1
];
struct
聽Node{ 聽聽聽聽
int
聽x,聽y,聽ht; 聽聽聽聽Node(聽
int
聽a
=
聽
0
,聽
int
聽b
=
聽
0
,聽
int
聽c
=
聽
0
聽):x(a),聽y(b),聽ht(c)聽{} };
bool
聽
operator
<
(聽Node聽
const
&
聽a,聽Node聽
const
&
b聽){ 聽聽聽聽
return
聽a.ht
<
聽b.ht;聽} Node聽xyh[N];
int
聽bsearch(聽
int
聽v聽){ 聽聽聽聽
int
聽left
=
聽
0
,聽right
=
聽n
*
聽
2
; 聽聽聽聽
while
(聽left
+
聽
1
<
聽right聽){ 聽聽聽聽聽聽聽聽
int
聽m
=
聽(left
+
right)
>>
1
; 聽聽聽聽聽聽聽聽
if
(聽d[m]
>
聽v聽)聽right
=
聽m; 聽聽聽聽聽聽聽聽
else
聽
if
(聽d[m]
<
聽v聽)聽left
=
聽m; 聽聽聽聽聽聽聽聽
else
聽
return
聽idx[m]; 聽聽聽聽} 聽聽聽聽
return
聽idx[left];聽}
int
聽tb[N
*
8
]
=
聽{
0
};
void
聽insert(聽
int
聽l,聽
int
聽r,聽
int
聽a,聽
int
聽b,聽
int
聽rt,聽
int
聽h聽){ 聽聽聽聽
if
(聽l
==
聽a聽
&&
聽r
==
聽b聽){ 聽聽聽聽聽聽聽聽tb[rt]
=
聽max(聽tb[rt],聽h聽);聽
return
;聽} 聽聽聽聽
if
(聽tb[rt]
!=
聽
0
聽){ 聽聽聽聽聽聽聽聽tb[rt
<<
1
]
=
聽tb[rt]; 聽聽聽聽聽聽聽聽tb[(rt
<<
1
)
+
1
]
=
聽tb[rt]; 聽聽聽聽聽聽聽聽tb[rt]
=
聽
0
;聽} 聽聽聽聽
int
聽m
=
聽(l
+
聽r)
>>
1
; 聽聽聽聽
if
(聽b
<=
聽m聽)聽insert(聽l,聽m,聽a,聽b,聽rt
<<
聽
1
,聽h聽); 聽聽聽聽
else
聽
if
(聽a
>=
聽m聽)聽insert(聽m,聽r,聽a,聽b,聽(rt
<<
1
)
+
聽
1
,聽h聽); 聽聽聽聽
else
{ 聽聽聽聽聽聽聽聽insert(聽l,聽m,聽a,聽m,聽rt
<<
聽
1
,聽h聽); 聽聽聽聽聽聽聽聽insert(聽m,聽r,聽m,聽b,聽(rt
<<
1
)
+
聽
1
,聽h聽);聽} } typedef聽__int64聽INT; INT聽ans;
void
聽sum(聽
int
聽l,聽
int
聽r,聽
int
聽rt聽){ 聽聽聽聽
if
(聽tb[rt]
>
聽
0
聽){ 聽聽聽聽聽聽聽聽ans
=
聽ans
+
聽(INT)(聽f[r]
-
聽f[l]聽)
*
聽(INT)tb[rt]; 聽聽聽聽聽聽聽聽
return
;聽} 聽聽聽聽
if
(聽r
>
聽l
+
聽
1
聽){ 聽聽聽聽聽聽聽聽
int
聽m
=
聽(l
+
聽r)
>>
聽
1
; 聽聽聽聽聽聽聽聽sum(聽l,聽m,聽rt
<<
聽
1
聽); 聽聽聽聽聽聽聽聽sum(聽m,聽r,聽(rt
<<
1
)
+
聽
1
聽); 聽聽聽聽}聽聽聽聽聽聽聽聽 } inline聽
int
聽read(){ 聽聽聽聽
char
聽ch; 聽聽聽聽
int
聽d; 聽聽聽聽
while
(聽(ch
=
聽getchar()),聽ch
<
聽
'
0
'
聽
||
聽ch
>
聽
'
9
'
聽); 聽聽聽聽d
=
聽ch
-
聽
'
0
'
; 聽聽聽聽
while
(聽(ch
=
聽getchar()),聽ch
>=
聽
'
0
'
聽
&&
聽ch
<=
聽
'
9
'
聽)聽d
=
聽d
*
聽
10
+
聽ch
-
聽
'
0
'
; 聽聽聽聽
return
聽d;聽} 聽聽聽聽
int
聽main(){ 聽聽聽聽
int
聽a,聽b,聽h; 聽聽聽聽scanf(
"
%d
"
,
&
n); 聽聽聽聽
for
(聽
int
聽i
=
聽
0
;聽i
<
聽n;聽
++
i聽){ 聽聽聽聽聽聽聽聽a
=
聽read(),聽b
=
聽read(),聽h
=
聽read(); 聽聽聽聽聽聽聽聽xyh[i]
=
聽Node(聽a,聽b,聽h聽); 聽聽聽聽聽聽聽聽d[i
<<
1
]
=
聽a,聽d[(i
<<
1
)
+
1
]
=
聽b;聽} 聽聽聽聽sort(聽d,聽d
+
聽n
*
聽
2
聽); 聽聽聽聽pos
=
聽
1
;聽idx[
0
]
=
聽
1
;聽f[
1
]
=
聽d[
0
]; 聽聽聽聽
for
(聽
int
聽i
=
聽
1
;聽i
<
聽n
*
聽
2
;聽
++
i聽){ 聽聽聽聽聽聽聽聽
if
(聽d[i]
!=
聽d[i
-
1
]聽)聽idx[i]
=
聽
++
pos; 聽聽聽聽聽聽聽聽
else
聽idx[i]
=
聽idx[i
-
1
]; 聽聽聽聽聽聽聽聽f[聽idx[i]聽]
=
聽d[i]; 聽聽聽聽} 聽聽聽聽sort(聽xyh,聽xyh
+
聽n聽); 聽聽聽聽
for
(聽
int
聽i
=
聽
0
;聽i
<
聽n;聽
++
i聽){ 聽聽聽聽聽聽聽聽a
=
聽bsearch(聽xyh[i].x聽),聽b
=
聽bsearch(聽xyh[i].y聽); 聽聽聽聽聽聽聽聽insert(聽
1
,聽pos,聽a,聽b,聽
1
,聽xyh[i].ht聽); 聽聽聽聽}聽聽聽聽聽聽聽聽 聽聽聽聽ans
=
聽
0
;聽 聽聽聽聽sum(聽
1
,聽pos,聽
1
聽); 聽聽聽聽printf(
"
%I64d\n
"
,聽ans聽); 聽聽聽聽 聽聽聽聽
return
聽
0
; }
]]> Pku 2528 Mayor's posters http://www.shnenglu.com/Darren/archive/2009/07/14/90068.htmlDarren Darren Tue, 14 Jul 2009 12:19:00 GMT http://www.shnenglu.com/Darren/archive/2009/07/14/90068.html http://www.shnenglu.com/Darren/comments/90068.html http://www.shnenglu.com/Darren/archive/2009/07/14/90068.html#Feedback 0 http://www.shnenglu.com/Darren/comments/commentRss/90068.html http://www.shnenglu.com/Darren/services/trackbacks/90068.html
#include聽
<
iostream
>
#include聽
<
algorithm
>
using
聽
namespace
聽std;
#define
聽N聽10010
struct
聽Node{ 聽聽聽聽
int
聽x,聽y; 聽聽聽聽Node(聽
int
聽a
=
聽
0
,聽
int
聽b
=
聽
0
聽):x(a),聽y(b)聽{} };
int
聽聽n,聽idx[N
*
2
],聽data[N
*
2
],聽pos; Node聽d[N];
int
聽bfind(聽
int
聽v聽){ 聽聽聽聽
int
聽left
=
聽
0
,聽right
=
聽n
*
聽
2
; 聽聽聽聽
while
(聽left
+
聽
1
<
聽right聽){ 聽聽聽聽聽聽聽聽
int
聽m
=
聽(left
+
聽right)
>>
聽
1
; 聽聽聽聽聽聽聽聽
if
(聽data[m]
<
聽v聽)聽left
=
聽m; 聽聽聽聽聽聽聽聽
else
聽
if
(聽data[m]
>
聽v聽)聽right
=
聽m; 聽聽聽聽聽聽聽聽
else
聽
return
聽idx[m]; 聽聽聽聽} 聽聽聽聽
return
聽idx[left]; }
int
聽tb[N
*
8
],聽flag[N];
void
聽insert(聽
int
聽l,聽
int
聽r,聽
int
聽a,聽
int
聽b,聽
int
聽rt,聽
int
聽c聽){ 聽聽聽聽
if
(聽l
==
聽a聽
&&
聽r
==
聽b聽){ 聽聽聽聽聽聽聽聽tb[rt]
=
聽c;聽
return
;聽} 聽聽聽聽
int
聽m
=
聽(l
+
聽r)
>>
聽
1
; 聽聽聽聽
if
(聽tb[rt]
>
聽
0
聽){ 聽聽聽聽聽聽聽聽tb[rt
<<
1
]
=
聽tb[rt],聽tb[(rt
<<
1
)
+
1
]
=
聽tb[rt],聽tb[rt]
=
聽
0
;聽} 聽聽聽聽
if
(聽b
<=
聽m聽)聽insert(聽l,聽m,聽a,聽b,聽rt
<<
聽
1
,聽c聽); 聽聽聽聽
else
聽
if
(聽a
>
聽m聽)聽insert(聽m
+
聽
1
,聽r,聽a,聽b,聽(rt
<<
1
)
+
聽
1
,聽c聽); 聽聽聽聽
else
{ 聽聽聽聽聽聽聽聽insert(聽l,聽m,聽a,聽m,聽rt
<<
聽
1
,聽c聽); 聽聽聽聽聽聽聽聽insert(聽m
+
聽
1
,聽r,聽m
+
聽
1
,聽b,聽(rt
<<
1
)
+
聽
1
,聽c聽);聽} }
void
聽calc(聽
int
聽l,聽
int
聽r,聽
int
聽rt聽){ 聽聽聽聽
if
(聽tb[rt]
>
聽
0
聽)聽{聽flag[聽tb[rt]聽]
=
聽
1
;聽
return
;聽} 聽聽聽聽
else
{ 聽聽聽聽聽聽聽聽
if
(聽l
==
聽r聽)聽
return
; 聽聽聽聽聽聽聽聽
int
聽m
=
聽(l
+
聽r)
>>
聽
1
; 聽聽聽聽聽聽聽聽calc(聽l,聽m,聽rt
<<
聽
1
聽); 聽聽聽聽聽聽聽聽calc(聽m
+
聽
1
,聽r,聽(rt
<<
1
)
+
聽
1
聽); 聽聽聽聽} }
int
聽main(){ 聽聽聽聽
int
聽test; 聽聽聽聽scanf(
"
%d
"
,
&
test); 聽聽聽聽
while
(聽test
--
聽){ 聽聽聽聽聽聽聽聽scanf(
"
%d
"
,
&
n聽); 聽聽聽聽聽聽聽聽
int
聽u,聽v; 聽聽聽聽聽聽聽聽
for
(聽
int
聽i
=
聽
0
;聽i
<
聽n;聽
++
i聽){ 聽聽聽聽聽聽聽聽聽聽聽聽scanf(
"
%d%d
"
,
&
u,
&
v聽); 聽聽聽聽聽聽聽聽聽聽聽聽d[i]
=
聽Node(聽u,聽v聽); 聽聽聽聽聽聽聽聽聽聽聽聽data[i
<<
1
]
=
聽u,聽data[(i
<<
1
)
+
1
]
=
聽v; 聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽sort(聽data,聽data
+
聽n
*
聽
2
聽); 聽聽聽聽聽聽聽聽pos
=
聽
1
;聽idx[
0
]
=
聽
1
; 聽聽聽聽聽聽聽聽
for
(聽
int
聽i
=
聽
1
;聽i
<
聽n
*
聽
2
;聽
++
i聽) 聽聽聽聽聽聽聽聽
if
(聽data[i]
!=
聽data[i
-
1
]聽)聽idx[i]
=
聽
++
pos; 聽聽聽聽聽聽聽聽
else
聽聽idx[i]
=
聽pos; 聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽memset(聽tb,聽
0
,聽
sizeof
(tb)聽);聽 聽聽聽聽聽聽聽聽memset(聽flag,聽
0
,聽
sizeof
(flag)聽); 聽聽聽聽聽聽聽聽
for
(聽
int
聽i
=
聽
0
;聽i
<
聽n;聽
++
i聽){ 聽聽聽聽聽聽聽聽聽聽聽聽u
=
聽bfind(聽d[i].x聽),聽v
=
聽bfind(聽d[i].y聽); 聽聽聽聽聽聽聽聽聽聽聽聽insert(聽
1
,聽pos,聽u,聽v,聽
1
,聽i
+
聽
1
聽); 聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽calc(聽
1
,聽pos,聽
1
聽); 聽聽聽聽聽聽聽聽
int
聽ans
=
聽
0
; 聽聽聽聽聽聽聽聽
for
(聽
int
聽i
=
聽
1
;聽i
<=
聽n;聽
++
i聽) 聽聽聽聽聽聽聽聽
if
(聽flag[i]聽)聽ans
++
; 聽聽聽聽聽聽聽聽printf(
"
%d\n
"
,聽ans聽); 聽聽聽聽} 聽聽聽聽
return
聽
0
; }
]]> Pku 2985 The k-th Largest Group http://www.shnenglu.com/Darren/archive/2009/07/14/90014.htmlDarren Darren Tue, 14 Jul 2009 05:31:00 GMT http://www.shnenglu.com/Darren/archive/2009/07/14/90014.html http://www.shnenglu.com/Darren/comments/90014.html http://www.shnenglu.com/Darren/archive/2009/07/14/90014.html#Feedback 0 http://www.shnenglu.com/Darren/comments/commentRss/90014.html http://www.shnenglu.com/Darren/services/trackbacks/90014.html
#include聽
<
iostream
>
using
聽
namespace
聽std;
int
聽n,聽m;
#define
聽N聽聽200010
#define
聽lowbit(x)聽聽(聽(x)&(-(x))聽)
struct
聽TArray{ 聽聽聽聽
int
聽cnt[N]; 聽聽聽聽TArray(){聽init();聽} 聽聽聽聽
void
聽update(聽
int
聽p,聽
int
聽v聽){ 聽聽聽聽聽聽聽聽
for
(聽
int
聽x
=
聽p;聽x
<=
聽n;聽cnt[x]
+=
聽v,聽x
+=
聽lowbit(x)聽);聽} 聽聽聽聽
int
聽聽sum(聽
int
聽p聽){ 聽聽聽聽聽聽聽聽
int
聽x
=
聽p,聽s
=
聽
0
; 聽聽聽聽聽聽聽聽
for
(聽;聽x;聽s
+=
聽cnt[x],聽x
-=
聽lowbit(x)聽); 聽聽聽聽聽聽聽聽
return
聽s;聽} 聽聽聽聽
int
聽聽rank(聽
int
聽k聽){ 聽聽聽聽聽聽聽聽k
=
聽sum(n)
+
聽
1
-
聽k; 聽聽聽聽聽聽聽聽
int
聽left
=
聽
1
,聽right
=
聽n; 聽聽聽聽聽聽聽聽
while
(聽left
+
聽
1
<
聽right聽){ 聽聽聽聽聽聽聽聽聽聽聽聽
int
聽m
=
聽(left
+
聽right)
>>
聽
1
; 聽聽聽聽聽聽聽聽聽聽聽聽
int
聽s
=
聽sum(m); 聽聽聽聽聽聽聽聽聽聽聽聽
if
(聽s
>=
聽k聽)聽right
=
聽m; 聽聽聽聽聽聽聽聽聽聽聽聽
else
聽聽聽聽聽聽聽聽left
=
聽m; 聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽
if
(聽sum(left)
>=
聽k聽)聽
return
聽left; 聽聽聽聽聽聽聽聽
return
聽right; 聽聽聽聽} 聽聽聽聽
void
聽init(){聽聽
for
(
int
聽i
=
聽
0
;聽i
<=
聽n;聽
++
i聽)聽cnt[i]
=
聽
0
;聽} }; TArray聽tay;
struct
聽U_find{ 聽聽聽聽
int
聽find[N],聽num[N]; 聽聽聽聽U_find(){聽clear();} 聽聽聽聽
int
聽parent(聽
int
聽t聽){聽 聽聽聽聽聽聽聽聽
int
聽u
=
聽t,聽v;聽聽聽
while
(聽u
!=
聽find[u]聽)聽u
=
聽find[u]; 聽聽聽聽聽聽聽聽
while
(聽t
!=
聽u聽)聽{聽v
=
聽find[t];聽find[t]
=
聽u;聽t
=
聽find[v];聽} 聽聽聽聽聽聽聽聽
return
聽u;聽聽} 聽聽聽聽
bool
聽is_friend(聽
int
聽u,聽
int
聽v聽){聽
return
聽parent(u)
==
聽parent(v);聽} 聽聽聽聽
void
聽set_friend(聽
int
聽u,聽
int
聽v聽){ 聽聽聽聽聽聽聽聽
int
聽a
=
聽parent(u),聽b
=
聽parent(v); 聽聽聽聽聽聽聽聽
if
(聽a
==
聽b聽)聽
return
; 聽聽聽聽聽聽聽聽
if
(聽num[a]
>
聽num[b]聽)聽{聽 聽聽聽聽聽聽聽聽聽聽聽聽find[b]
=
聽a;聽聽 聽聽聽聽聽聽聽聽聽聽聽聽tay.update(聽num[b],聽
-
1
聽); 聽聽聽聽聽聽聽聽聽聽聽聽tay.update(聽num[a],聽
-
1
聽); 聽聽聽聽聽聽聽聽聽聽聽聽num[a]
+=
聽num[b]; 聽聽聽聽聽聽聽聽聽聽聽聽tay.update(聽num[a],聽
1
聽); 聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽
else
聽{ 聽聽聽聽聽聽聽聽聽聽聽聽find[a]
=
聽b; 聽聽聽聽聽聽聽聽聽聽聽聽tay.update(聽聽num[a],聽
-
1
聽); 聽聽聽聽聽聽聽聽聽聽聽聽tay.update(聽聽num[b],聽
-
1
聽); 聽聽聽聽聽聽聽聽聽聽聽聽num[b]
+=
聽num[a]; 聽聽聽聽聽聽聽聽聽聽聽聽tay.update(聽num[b],聽
1
聽); 聽聽聽聽聽聽聽聽} 聽聽聽聽} 聽聽聽聽
void
聽clear(){聽
for
(聽
int
聽i
=
聽
0
;聽i
<
聽N;聽
++
i聽)聽find[i]
=
聽i,聽num[i]
=
聽
1
;聽} }; U_find聽uf;
int
聽main(){ 聽聽聽聽scanf(
"
%d%d
"
,
&
n,
&
m聽); 聽聽聽聽tay.update(聽
1
,聽n聽); 聽聽聽聽 聽聽聽聽
while
(聽m
--
聽){ 聽聽聽聽聽聽聽聽
int
聽t,聽u,聽v,聽k; 聽聽聽聽聽聽聽聽scanf(
"
%d
"
,
&
t聽); 聽聽聽聽聽聽聽聽
if
(聽t
==
聽
0
聽){ 聽聽聽聽聽聽聽聽聽聽聽聽scanf(
"
%d%d
"
,
&
u,
&
v聽); 聽聽聽聽聽聽聽聽聽聽聽聽uf.set_friend(聽u,聽v聽聽); 聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽
else
{ 聽聽聽聽聽聽聽聽聽聽聽聽scanf(
"
%d
"
,
&
k聽); 聽聽聽聽聽聽聽聽聽聽聽聽printf(
"
%d\n
"
,聽tay.rank(k)聽); 聽聽聽聽聽聽聽聽} 聽聽聽聽} 聽聽聽聽
return
聽
0
; }
]]> Pku 2777 Count Color http://www.shnenglu.com/Darren/archive/2009/07/14/90001.htmlDarren Darren Tue, 14 Jul 2009 02:50:00 GMT http://www.shnenglu.com/Darren/archive/2009/07/14/90001.html http://www.shnenglu.com/Darren/comments/90001.html http://www.shnenglu.com/Darren/archive/2009/07/14/90001.html#Feedback 0 http://www.shnenglu.com/Darren/comments/commentRss/90001.html http://www.shnenglu.com/Darren/services/trackbacks/90001.html
#include聽
<
iostream
>
#include聽
<
cstdio
>
#include聽
<
cstdlib
>
#include聽
<
cstring
>
using
聽
namespace
聽std;
int
聽L,聽T,聽O;
int
聽tb[
300000
]
=
聽{
0
};
void
聽insert(聽
int
聽l,聽
int
聽r,聽
int
聽a,聽
int
聽b,聽
int
聽rt,聽
int
聽c聽){ 聽聽聽聽
if
(聽l
==
聽a聽
&&
聽r
==
聽b聽){ 聽聽聽聽聽聽聽聽tb[rt]
=
聽c;聽
return
;聽} 聽聽聽聽
if
(聽tb[rt]
>
聽
0
聽){ 聽聽聽聽聽聽聽聽tb[rt
<<
1
]
=
聽tb[rt],聽tb[(rt
<<
1
)
+
1
]
=
聽tb[rt];聽tb[rt]
=
聽
0
;聽} 聽聽聽聽
int
聽m
=
聽(l
+
聽r)
>>
聽
1
; 聽聽聽聽
if
(聽b
<=
聽m聽)聽insert(聽l,聽m,聽a,聽b,聽rt
<<
聽
1
,聽c聽); 聽聽聽聽
else
聽
if
(聽a
>
聽m聽)聽insert(聽m
+
聽
1
,聽r,聽a,聽b,聽(rt
<<
1
)
+
聽
1
,聽c聽); 聽聽聽聽
else
聽{ 聽聽聽聽聽聽聽聽insert(聽l,聽m,聽a,聽m,聽rt
<<
聽
1
,聽c聽); 聽聽聽聽聽聽聽聽insert(聽m
+
聽
1
,聽r,聽m
+
聽
1
,聽b,聽(rt
<<
1
)
+
聽
1
,聽c聽);聽} }
void
聽query(聽
int
聽l,聽
int
聽r,聽
int
聽a,聽
int
聽b,聽
int
聽rt,聽
int
&
聽ans聽){ 聽聽聽聽
if
(聽l
==
聽a聽
&&
聽r
==
聽b聽
&&
聽tb[rt]
>
聽
0
聽){ 聽聽聽聽聽聽聽聽ans
|=
聽(
1
<<
tb[rt]);聽
return
;聽聽} 聽聽聽聽
if
(聽tb[rt]
>
聽
0
聽){ 聽聽聽聽聽聽聽聽tb[rt
<<
1
]
=
聽tb[rt],聽tb[(rt
<<
1
)
+
1
]
=
聽tb[rt];聽} 聽聽聽聽
int
聽m
=
聽(l
+
聽r)
>>
聽
1
; 聽聽聽聽
if
(聽b
<=
聽m聽)聽query(聽l,聽m,聽a,聽b,聽rt
<<
聽
1
,聽ans聽); 聽聽聽聽
else
聽
if
(聽a
>
聽m聽)聽query(聽m
+
聽
1
,聽r,聽a,聽b,聽(rt
<<
1
)
+
聽
1
,聽ans聽); 聽聽聽聽
else
{ 聽聽聽聽聽聽聽聽query(聽l,聽m,聽a,聽m,聽rt
<<
聽
1
,聽ans聽); 聽聽聽聽聽聽聽聽query(聽m
+
聽
1
,聽r,聽m
+
聽
1
,聽b,聽(rt
<<
1
)
+
聽
1
,聽ans聽);聽} }
int
聽getnum(聽
int
聽t聽){ 聽聽聽聽
int
聽ans
=
聽
0
; 聽聽聽聽
for
(聽
int
聽i
=
聽
1
;聽i
<=
聽T;聽
++
i聽) 聽聽聽聽
if
(聽t
&
聽(
1
<<
i聽)聽)聽ans
++
; 聽聽聽聽
return
聽ans;}
int
聽main(){ 聽聽聽聽scanf(
"
%d%d%d
"
,
&
L,聽
&
T,聽
&
O聽); 聽聽聽聽tb[
1
]
=
聽
1
; 聽聽聽聽
char
聽str[
5
]; 聽聽聽聽
int
聽a,聽b,聽c,聽d; 聽聽聽聽
while
(聽O
--
聽){ 聽聽聽聽聽聽聽聽scanf(
"
%s
"
,聽str聽); 聽聽聽聽聽聽聽聽
if
(聽str[
0
]
==
聽
'
C
'
聽){ 聽聽聽聽聽聽聽聽聽聽聽聽scanf(
"
%d%d%d
"
,
&
a,
&
b,
&
c聽); 聽聽聽聽聽聽聽聽聽聽聽聽
if
(聽a
>
聽b聽)聽{聽d
=
聽a;聽a
=
聽b;聽b
=
聽d;聽} 聽聽聽聽聽聽聽聽聽聽聽聽insert(聽
1
,聽L,聽a,聽b,聽
1
,聽c聽); 聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽
else
{ 聽聽聽聽聽聽聽聽聽聽聽聽scanf(
"
%d%d
"
,
&
a,
&
b聽);聽c
=
聽
0
; 聽聽聽聽聽聽聽聽聽聽聽聽
if
(聽a
>
聽b聽)聽{聽d
=
聽a;聽a
=
聽b;聽b
=
聽d;聽} 聽聽聽聽聽聽聽聽聽聽聽聽query(聽
1
,聽L,聽a,聽b,聽
1
,聽c聽); 聽聽聽聽聽聽聽聽聽聽聽聽printf(
"
%d\n
"
,聽getnum(c)聽); 聽聽聽聽聽聽聽聽} 聽聽聽聽} 聽聽聽聽
return
聽
0
; }
]]> ZJU 2770 Burn the Linked Camp(宸垎綰︽潫緋葷粺) http://www.shnenglu.com/Darren/archive/2009/07/11/89797.htmlDarren Darren Sat, 11 Jul 2009 07:32:00 GMT http://www.shnenglu.com/Darren/archive/2009/07/11/89797.html http://www.shnenglu.com/Darren/comments/89797.html http://www.shnenglu.com/Darren/archive/2009/07/11/89797.html#Feedback 0 http://www.shnenglu.com/Darren/comments/commentRss/89797.html http://www.shnenglu.com/Darren/services/trackbacks/89797.html
#include聽
<
iostream
>
#include聽
<
vector
>
using
聽
namespace
聽std;
struct
聽Edge{ 聽聽聽聽
int
聽u,聽v,聽w; 聽聽聽聽Edge(聽
int
聽a
=
聽
0
,聽
int
聽b
=
聽
0
,聽
int
聽c
=
聽
0
聽): 聽聽聽聽聽聽聽聽u(a),聽v(b),聽w(c)聽{} };
int
聽n,聽m;
int
聽c[
1010
],聽sum[
1010
],聽dist[
1010
]; vector
<
Edge
>
聽ege;
bool
聽bellman(){ 聽聽聽聽memset(聽dist,聽
0
,聽
sizeof
(dist)聽);聽聽聽聽 聽聽聽聽
int
聽len
=
聽ege.size(); 聽聽聽聽
for
(聽
int
聽i
=
聽
0
;聽i
<
聽n;聽
++
i聽){ 聽聽聽聽聽聽聽聽
for
(聽
int
聽j
=
聽
0
;聽j
<
聽len;聽
++
j聽) 聽聽聽聽聽聽聽聽
if
(聽dist[聽ege[j].u聽]
+
聽ege[j].w
<
聽dist[聽ege[j].v聽]聽) 聽聽聽聽聽聽聽聽dist[聽ege[j].v聽]
=
聽dist[聽ege[j].u聽]
+
聽ege[j].w; 聽聽聽聽} 聽聽聽聽
bool
聽flag
=
聽
false
; 聽聽聽聽
for
(聽
int
聽j
=
聽
0
;聽j
<
聽len;聽
++
j聽) 聽聽聽聽
if
(聽dist[聽ege[j].u聽]
+
聽ege[j].w
<
聽dist[聽ege[j].v聽]聽) 聽聽聽聽
return
聽
false
; 聽聽聽聽 聽聽聽聽
return
聽
true
; }
int
聽main(){ 聽聽聽聽
while
(聽scanf(
"
%d%d
"
,
&
n,
&
m)
!=
聽EOF聽){ 聽聽聽聽聽聽聽聽memset(聽sum,聽
0
,聽
sizeof
(sum)聽); 聽聽聽聽聽聽聽聽
for
(聽
int
聽i
=
聽
1
;聽i
<=
聽n;聽
++
i聽){ 聽聽聽聽聽聽聽聽聽聽聽聽聽scanf(
"
%d
"
,聽c
+
聽i聽); 聽聽聽聽聽聽聽聽聽聽聽聽聽sum[i]
=
聽sum[i
-
1
]
+
聽c[i]; 聽聽聽聽聽聽聽聽聽聽聽聽聽ege.push_back(聽Edge(聽i
-
1
,聽i,聽c[i]聽)聽); 聽聽聽聽聽聽聽聽聽聽聽聽聽ege.push_back(聽Edge(聽i,聽i
-
1
,聽
0
聽)聽); 聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽
int
聽u,聽v,聽w; 聽聽聽聽聽聽聽聽
while
(聽m
--
聽){ 聽聽聽聽聽聽聽聽聽聽聽聽scanf(
"
%d%d%d
"
,
&
u,
&
v,
&
w聽); 聽聽聽聽聽聽聽聽聽聽聽聽u
--
; 聽聽聽聽聽聽聽聽聽聽聽聽ege.push_back(聽Edge(聽v,聽u,聽
-
w聽)聽); 聽聽聽聽聽聽聽聽聽聽聽聽ege.push_back(聽Edge(聽u,聽v,聽sum[v]
-
聽sum[u]聽)聽); 聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽
if
(聽
!
bellman()聽)聽puts(
"
Bad聽Estimations
"
); 聽聽聽聽聽聽聽聽
else
聽聽聽聽聽聽聽聽聽聽聽聽聽printf(
"
%d\n
"
,dist[n]
-
聽dist[
0
]聽); 聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽ege.clear(); 聽聽聽聽} 聽聽聽聽 聽聽聽聽
return
聽
0
; }
]]> Pku 2777 Count Color http://www.shnenglu.com/Darren/archive/2008/10/12/63794.htmlDarren Darren Sun, 12 Oct 2008 04:45:00 GMT http://www.shnenglu.com/Darren/archive/2008/10/12/63794.html http://www.shnenglu.com/Darren/comments/63794.html http://www.shnenglu.com/Darren/archive/2008/10/12/63794.html#Feedback 0 http://www.shnenglu.com/Darren/comments/commentRss/63794.html http://www.shnenglu.com/Darren/services/trackbacks/63794.html
#include聽
<
stdio.h
>
#include聽
<
stdlib.h
>
#include聽
<
algorithm
>
#define
聽single(x)聽(聽(聽(x)&(聽(x)-1聽)聽)==聽0聽)
struct
聽聽Node
{ 聽聽聽聽
int
聽left,right,colour; 聽聽聽聽Node
*
聽lchild,聽
*
rchild; }
; Node
*
聽create(聽Node
*
聽t,聽
int
聽a,聽
int
聽b聽)
{ 聽聽聽聽t
=
聽
new
聽Node; 聽聽聽聽 聽聽聽聽t
->
left
=
聽a;聽t
->
right
=
聽b;聽t
->
colour
=
聽
1
; 聽聽聽聽t
->
lchild
=
聽NULL;聽t
->
rchild
=
聽NULL; 聽聽聽聽 聽聽聽聽
if
(聽a
<
聽b聽)
{ 聽聽聽聽聽聽聽聽t
->
lchild
=
聽create(聽t
->
lchild,聽a,聽(a
+
b)
/
2
聽); 聽聽聽聽聽聽聽聽t
->
rchild
=
聽create(聽t
->
rchild,聽(a
+
b)
/
2
+
1
,聽b聽); 聽聽聽聽}
聽聽聽聽 聽聽聽聽
return
聽t; }
void
聽insert(聽Node
*
聽root,聽
int
聽a,
int
聽b,聽
int
聽c聽)
{ 聽聽聽聽
if
(聽root
->
left
==
聽a聽
&&
聽root
->
right
==
聽b聽
||
聽root
->
colour
==
聽c聽) 聽聽聽聽
{ 聽聽聽聽聽聽聽聽root
->
colour
=
聽c; 聽聽聽聽聽聽聽聽
return
; 聽聽聽聽}
聽聽聽聽
if
(聽single(root
->
colour聽)聽) 聽聽聽聽
{ 聽聽聽聽聽聽聽聽root
->
lchild
->
colour
=
root
->
colour; 聽聽聽聽聽聽聽聽root
->
rchild
->
colour
=
root
->
colour; 聽聽聽聽}
聽聽聽聽 聽聽聽聽
int
聽middle
=
聽(root
->
left
+
聽root
->
right)
/
聽
2
; 聽聽聽聽 聽聽聽聽
if
(聽b
<=
聽middle聽)聽聽聽聽聽聽insert(聽root
->
lchild,聽a,聽b,聽c聽); 聽聽聽聽
else
聽
if
(聽a
>
聽middle聽)聽聽insert(聽root
->
rchild,聽a,聽b,聽c聽); 聽聽聽聽
else
{ 聽聽聽聽聽聽聽聽insert(聽root
->
lchild,聽a,聽middle,聽c聽); 聽聽聽聽聽聽聽聽insert(聽root
->
rchild,聽middle
+
聽
1
,聽b,聽c聽); 聽聽聽聽}
聽聽聽聽 聽聽聽聽
if
(聽root
->
lchild聽
&&
聽root
->
rchild聽) 聽聽聽聽root
->
colour
=
聽root
->
lchild
->
colour聽
|
聽root
->
rchild
->
colour; }
void
聽getcout(聽Node
*
聽root,聽
int
聽a,聽
int
聽b,聽
int
&
聽cnt聽)
{ 聽聽聽聽
if
(聽root
->
left
==
聽a聽
&&
聽root
->
right
==
聽b聽
||
聽single(root
->
colour聽)聽) 聽聽聽聽
{ 聽聽聽聽聽聽聽聽cnt
=
聽cnt
|
root
->
colour; 聽聽聽聽聽聽聽聽
return
; 聽聽聽聽}
聽聽聽聽 聽聽聽聽
int
聽middle
=
聽(root
->
left
+
聽root
->
right)
/
聽
2
; 聽聽聽聽 聽聽聽聽
if
(聽b
<=
聽middle聽)聽聽聽聽聽聽聽getcout(聽root
->
lchild,聽a,聽b,聽cnt聽); 聽聽聽聽
else
聽
if
(聽a
>
聽middle聽)聽聽聽getcout(聽root
->
rchild,聽a,聽b,聽cnt聽); 聽聽聽聽
else
{ 聽聽聽聽聽聽聽聽getcout(聽root
->
lchild,聽a,聽middle,聽聽聽聽cnt聽); 聽聽聽聽聽聽聽聽getcout(聽root
->
rchild,聽middle
+
聽
1
,聽b,聽cnt聽); 聽聽聽聽}
}
int
聽count(聽
int
聽i聽)
{ 聽聽聽聽
int
聽ans
=
聽
0
; 聽聽聽聽
while
(聽i
>
聽
0
聽) 聽聽聽聽
{ 聽聽聽聽聽聽聽聽
if
(聽i
&
1
聽)聽ans
++
; 聽聽聽聽聽聽聽聽i
>>=
1
; 聽聽聽聽}
聽聽聽聽
return
聽ans; }
聽聽聽聽聽聽聽聽
int
聽main()
{ 聽聽聽聽Node
*
聽root; 聽聽聽聽
int
聽l,聽t,聽o; 聽聽聽聽 聽聽聽聽scanf(
"
%d%d%d
"
,
&
l,
&
t,
&
o聽); 聽聽聽聽root
=
聽create(聽root,聽
1
,l聽); 聽聽聽聽 聽聽聽聽
char
聽str[
5
]; 聽聽聽聽
for
(聽
int
聽i
=
聽
0
;聽i
<
聽o;聽
++
i聽) 聽聽聽聽
{ 聽聽聽聽聽聽聽聽scanf(
"
%s
"
,str); 聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽
if
(聽str[
0
]
==
聽
'
C
'
聽) 聽聽聽聽聽聽聽聽
{ 聽聽聽聽聽聽聽聽聽聽聽聽
int
聽x,聽y,聽z; 聽聽聽聽聽聽聽聽聽聽聽聽scanf(
"
%d%d%d
"
,
&
x,
&
y,
&
z); 聽聽聽聽聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽聽聽聽聽
if
(聽x
>
聽y聽)聽std::swap(x,y); 聽聽聽聽聽聽聽聽聽聽聽聽insert(聽root,聽x,聽y,聽
1
<<
(z
-
聽
1
)聽); 聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽
else
聽
if
(聽str[
0
]
==
聽
'
P
'
聽) 聽聽聽聽聽聽聽聽
{ 聽聽聽聽聽聽聽聽聽聽聽聽
int
聽x,聽y,cnt
=
聽
0
; 聽聽聽聽聽聽聽聽聽聽聽聽scanf(
"
%d%d
"
,
&
x,
&
y); 聽聽聽聽聽聽聽聽聽聽聽聽
if
(聽x
>
聽y聽)聽std::swap(x,y); 聽聽聽聽聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽聽聽聽聽getcout(聽root,聽x,聽y,聽cnt聽); 聽聽聽聽聽聽聽聽聽聽聽聽printf(
"
%d\n
"
,聽count(cnt)聽); 聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽
return
聽
0
; }
]]> Zoj 1610 Count the Colors http://www.shnenglu.com/Darren/archive/2008/10/08/63459.htmlDarren Darren Wed, 08 Oct 2008 06:29:00 GMT http://www.shnenglu.com/Darren/archive/2008/10/08/63459.html http://www.shnenglu.com/Darren/comments/63459.html http://www.shnenglu.com/Darren/archive/2008/10/08/63459.html#Feedback 1 http://www.shnenglu.com/Darren/comments/commentRss/63459.html http://www.shnenglu.com/Darren/services/trackbacks/63459.html
#include聽
<
stdio.h
>
#include聽
<
stdlib.h
>
#include聽
<
string
.h
>
#define
聽NOC聽-1
#define
聽MUC聽-2
#define
聽N聽聽聽8001
#define
聽M聽聽聽10000
struct
聽聽Node
{ 聽聽聽聽
int
聽聽leftvalue; 聽聽聽聽
int
聽聽rightvalue; 聽聽聽聽
int
聽聽colour; 聽聽聽聽 聽聽聽聽Node
*
聽聽leftchild; 聽聽聽聽Node
*
聽聽rightchild; }
;
int
聽聽聽colour[M]; Node
*
聽create(聽Node
*
聽r,聽
int
聽left,聽
int
聽right聽)
{聽聽聽聽 聽聽聽聽Node
*
聽temp
=
聽
new
聽Node; 聽聽聽聽 聽聽聽聽temp
->
leftvalue
=
聽left; 聽聽聽聽temp
->
rightvalue
=
聽right; 聽聽聽聽temp
->
colour
=
聽NOC; 聽聽聽聽 聽聽聽聽temp
->
rightchild
=
聽NULL; 聽聽聽聽temp
->
leftchild
=
聽NULL; 聽聽聽聽聽聽聽聽 聽聽聽聽
if
聽(聽right
-
聽left
==
聽
1
聽)聽
return
聽temp; 聽聽聽聽
else
{聽 聽聽聽聽聽聽聽聽temp
->
leftchild
=
聽create(聽temp
->
leftchild,聽left,聽(left
+
聽right)
/
聽
2
聽); 聽聽聽聽聽聽聽聽temp
->
rightchild
=
聽create(聽temp
->
rightchild,聽(left
+
right)
/
聽
2
,聽right聽); 聽聽聽聽}
聽聽聽聽 聽聽聽聽
return
聽temp; }
聽聽聽聽聽聽聽
void
聽insert(聽Node
*
聽tree,聽
int
聽left,聽
int
聽right,聽
int
聽c聽)
{ 聽聽聽聽
int
聽middle
=
聽(聽tree
->
leftvalue
+
聽tree
->
rightvalue聽)
/
聽
2
; 聽聽聽聽 聽聽聽聽
if
聽(聽right
==
聽tree
->
rightvalue聽
&&
聽left
==
聽tree
->
leftvalue聽
||
聽tree
->
colour
==
聽c) 聽聽聽聽
{ 聽聽聽聽聽聽聽聽tree
->
colour
=
聽聽c; 聽聽聽聽聽聽聽聽
return
; 聽聽聽聽}
聽聽聽 聽聽聽聽 聽聽聽聽
if
聽(聽tree
->
colour聽
>=
聽
0
聽) 聽聽聽聽
{ 聽聽聽聽聽聽聽聽tree
->
leftchild
->
colour
=
聽tree
->
colour; 聽聽聽聽聽聽聽聽tree
->
rightchild
->
colour
=
聽tree
->
colour; 聽聽聽聽}
聽聽聽聽 聽聽聽聽聽聽聽聽 聽聽聽聽tree
->
colour
=
聽MUC; 聽聽聽聽
if
聽(聽middle
>=
聽right聽)聽聽聽聽聽聽聽insert(聽tree
->
leftchild,聽left,聽right,聽c聽); 聽聽聽聽
else
聽聽
if
聽(聽middle
<=
聽left聽)聽聽insert(聽tree
->
rightchild,聽left,聽right,c聽); 聽聽聽聽
else
聽聽聽聽
{聽聽聽 聽聽聽聽聽聽聽聽insert(聽tree
->
leftchild,聽left,聽middle,聽c聽); 聽聽聽聽聽聽聽聽insert(聽tree
->
rightchild,聽middle,聽right,聽c聽); 聽聽聽聽}
聽聽聽聽 聽聽聽聽聽聽聽 }
聽
void
聽getcolour(聽Node
*
聽tree,聽
int
&
聽col聽)
{ 聽聽聽聽
if
聽(聽tree
->
colour
>=
聽
0
聽
&&
聽tree
->
colour
!=
聽col聽) 聽聽聽聽
{ 聽聽聽聽聽聽聽聽col
=
聽tree
->
colour; 聽聽聽聽聽聽聽聽colour[聽tree
->
colour聽]
++
; 聽聽聽聽}
聽聽聽聽 聽聽聽聽
else
聽
if
聽(聽tree
->
colour
==
聽MUC聽) 聽聽聽聽
{ 聽聽聽聽聽聽聽聽getcolour(聽tree
->
leftchild,聽col聽); 聽聽聽聽聽聽聽聽getcolour(聽tree
->
rightchild,聽col聽); 聽聽聽聽}
聽聽聽聽
else
聽col
=
聽tree
->
colour;聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽聽聽聽聽
int
聽main()
{ 聽聽聽聽Node
*
聽root; 聽聽聽聽
int
聽聽聽n; 聽聽聽聽 聽聽聽聽
while
(聽scanf(
"
%d
"
,
&
n)
!=
聽EOF聽) 聽聽聽聽
{ 聽聽聽聽聽聽聽聽root
=
聽create(聽root,聽
0
,聽N聽); 聽聽聽聽聽聽聽聽
int
聽聽a,聽b,聽c; 聽聽聽聽聽聽聽聽
for
聽(聽
int
聽i
=
聽
0
;聽i
<
聽n;聽
++
i聽) 聽聽聽聽聽聽聽聽
{ 聽聽聽聽聽聽聽聽聽聽聽聽scanf(
"
%d%d%d
"
,
&
a,
&
b,
&
c); 聽聽聽聽聽聽聽聽聽聽聽聽insert(聽root,聽a,聽b,聽c聽); 聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽memset(聽colour,聽
0
,聽
sizeof
(colour)聽); 聽聽聽聽聽聽聽聽
int
聽col
=
聽
-
1
; 聽聽聽聽聽聽聽聽getcolour(聽root,聽col聽); 聽聽聽聽聽聽聽聽 聽聽聽聽聽聽聽聽
for
聽(聽
int
聽i
=
聽
0
;聽i
<
聽M;聽
++
i聽)聽 聽聽聽聽聽聽聽聽聽聽
if
聽(聽colour[i]聽)聽printf(
"
%d聽%d\n
"
,聽i,聽colour[i]聽);聽聽聽 聽聽聽聽聽聽聽聽printf(
"
\n
"
);聽聽聽聽 聽聽聽聽}
聽聽聽聽 聽聽聽聽 聽聽聽聽
return
聽
0
; }
聽聽聽聽聽聽聽聽
]]>
少妇久久久久久久久久 |
狠狠精品久久久无码中文字幕 |
一极黄色视频久久网站 |
色播久久人人爽人人爽人人片aV |
国产精品久久久久乳精品爆 |
国产日韩久久久精品影院首页 |
中文字幕无码av激情不卡久久 |
色综合合久久天天给综看 |
狠狠色丁香久久婷婷综合 |
国产精品久久久久久吹潮 |
成人午夜精品久久久久久久小说 |
一本一本久久A久久综合精品
|
91精品国产综合久久四虎久久无码一级 |
国产精品一久久香蕉产线看 |
久久久网中文字幕 |
久久福利片 |
国内精品久久久久久久久电影网 |
亚洲AV无码久久精品狠狠爱浪潮 |
久久精品国产第一区二区三区 |
久久人人爽人爽人人爽av |
国产成人久久精品区一区二区 |
国产免费久久久久久无码 |
亚洲精品无码久久千人斩 |
欧美亚洲国产精品久久久久 |
狠狠色婷婷久久一区二区 |
久久久久综合中文字幕 |
色综合久久久久网 |
久久久久国产精品三级网 |
国产精品无码久久综合 |
色综合久久88色综合天天
|
精品国产青草久久久久福利 |
亚洲国产精品成人久久 |
久久精品国产99国产电影网 |
久久综合中文字幕 |
天天爽天天爽天天片a久久网 |
久久久久女教师免费一区 |
久久久久综合国产欧美一区二区 |
青青草原综合久久 |
久久综合久久综合久久 |
久久亚洲精品人成综合网 |
久久综合综合久久97色 |