http://ai.pku.edu.cn/cpp2010 - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

http://ai.pku.edu.cn/cpp2010

Description:

... on the same number line. Farmer John has two modes of transportation: walking and teleporting. * Walking: FJ can move from any point X to the points X ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 30
Provided by: ying153
Category:
Tags: cpp2010 | edu | http | pku | teleporting

less

Transcript and Presenter's Notes

Title: http://ai.pku.edu.cn/cpp2010


1
??????
  • ???
  • http//ai.pku.edu.cn/cpp2010

2
???
2951 ???????? 2775 ????? 2787 ?24acm3278 catch
the cow Acm1321????
3
2951
????????? R ( 0.0 lt R lt 99.999 ) ,????????? R ?
n ???n ????? 0 lt n lt 25? ???????? R ? n? R ????
1 ? ? 6 ?, n ???? 8 ?? 9 ?? ????????,??????,?????
?? R ? n ???????????? 0 ??????? 0
????????,????????
4
2951
  • 95.123 12
  • 0.4321 20
  • 5.1234 15
  • 6.7592 9
  • 98.999 10
  • 1.0100 12

548815620517731830194541.8990253434157159735359672
21869852721 .0000000514855464107695612199451127676
7154838481760200726351203835429763013462401 439920
25569.92857370126648804114665499331870370751166629
5476720493953024 29448126.764121021618164430206909
037173276672 90429072743629540498.1075960194566517
74561044010001 1.126825030131969720661201
5
2951
  • ???95.123 12??
  • ???????? 3?
  • ?????,????95.123 -gt 95123
  • ?9512312 54881562051773183019454189902534341571
    5973535967221869852721
  • ??????548815620517731830194541.8990253434157159735
    35967221869852721

6
2951 ??
  • includeltstdio.hgt
  • includeltstring.hgt
  • const int MAX100
  • char s7
  • int aMAX,e,p,b,be,en,i
  • void mul()
  • int i,w0
  • for(i0iltMAXi)
  • aiaibw
  • wai/10
  • aiai-w10

7
  • int main()
  • while (scanf("s d",s,e)!EOF)
  • memset(a,0,sizeof(a))
  • b0 //Step 1 and Step 2
  • for(i0iltstrlen(s)i)
  • if (si'.') pstrlen(s)-i-1
  • else bb10si-'0'
  • a01 //Step 3
  • for(i0iltei)
  • mul()
  • pe //Step 4
  • for (beMAX-1abe0begtp-1be--)
  • for (en0aen0enltpen)
  • for (ibeigtpi--) printf("d",ai)
  • if (enltp) printf(".")
  • for (ip-1igteni--) printf("d",ai)
  • printf("\n")

8
2775 ?????
DATA SET 1 ROOT dir3 dir2
file1 file2
dir1 file1 file2 file3 file4 DATA SET
2 ROOT file1 file2
  • file1
  • file2
  • dir3
  • dir2
  • file1
  • file2
  • file4
  • dir1
  • file3
  • file2
  • file1

9
2775 ?????
??????????, ??????????????,???????????????????????
?. ???????????????????????????? ?????,?????????
?,?????,???????????,????,?????????,??????
file1 file2 dir3 dir2 file1 file2 file4 dir1
file3 file2 file1
10
include ltiostreamgt include ltvectorgt include
ltstringgt include ltalgorithmgt using namespace
std void ListDir( const char root)
//????? int nCurLevel 0 //??????????? int
MyCompare( const void e1, const void
e2) //??????????? return strcmp( (const char
) e1, (const char ) e2)
11
int main() int nDatasetNo 1 do cout
ltlt "DATA SET "ltlt nDatasetNo ltlt "" ltlt
endl nCurLevel 0 ListDir("ROOT")
//????? //???????test case char c do
//??????? c cin.peek() if( c '\r'
c '\n' ) cin.get() while( c '\r'
c '\n') if( c '') break else
cout ltlt endl nDatasetNo
while(1) return 0
12
void ListDir( const char root) char
sLine200 char vFiles20030 int
nTotalFiles 0 int i,j for( i 0i lt
nCurLevel i ) cout ltlt " " cout ltlt
root ltlt endl do cin gtgt sLine switch(
sLine0 ) case '' case '' qsort(
vFiles, nTotalFiles,30,MyCompare) for( j 0
j lt nTotalFiles j ) for( i 0i lt
nCurLevel i ) cout ltlt "
" cout ltltvFilesj ltlt endl nCurLe
vel --//????????,????? return
13
case 'f' strcpy( vFilesnTotalFiles
,sLine) break case 'd' nCurLevel
//????????,???? ListDir(
sLine) break while(1)
14
2787 ?24
  • ??
  • 5 5 5 1
  • 1 1 4 2
  • 0 0 0 0
  • ??
  • YES
  • NO

15
2787 ?24
  • ???k???24
  • ???k???24,???k-1???24
  • ???k????2??a?b,?????op?a?b?k?????,??(a op b)??

16
include ltiostreamgt using namespace std double
Numbers5 bool Calc( double pNumbers, int n
) //?pNumbers????n???24????? int main() int
a4 int nZeroNum 0 while(true) for(
int i 0i lt 4i ) cin gtgt
Numbersi if( Numbersi 0 ) nZeroNum
if( nZeroNum 4 ) break if(
Calc( Numbers,4)) cout ltlt "YES"
ltltendl else cout ltlt "NO" ltlt
endl return 0
17
bool Calc( double pNumbers, int n ) int
i,j,k double aNumber4 if( n 1 )
//?????????24,???????24,????? if( pNumbers0 gt
23.99999 pNumbers0 lt 24.00001 ) return
true else return false for( i 0i lt
n - 1i ) for( j i 1 j lt n j )
//??????? int m 0 for( k 0 k lt n k
) //??????? if( k ! i k ! j
) aNumberm pNumbersk //?????
?????,??????,???24 aNumberm pNumbersi
pNumbersj if( Calc( aNumber, n -1 ))
return true
18
aNumberm pNumbersi pNumbersj if(
Calc( aNumber, n -1 )) return
true aNumberm pNumbersi -
pNumbersj if( Calc( aNumber, n -1
)) return true aNumberm pNumbersj -
pNumbersi if( Calc( aNumber, n -1
)) return true if( pNumbersi ! 0)
aNumberm pNumbersj /
pNumbersi if( Calc( aNumber, n -1
)) return true if( pNumbersj !
0) aNumberm pNumbersi /
pNumbersj if( Calc( aNumber, n -1
)) return true return false
//?????????,??????
19
acm1321 ???? ??????????(?????????)??????,?????????
??????????????????????????,?????????????????,??k??
???????????C? Input ??????????? ??????????????,n
k,???????,???????nn????????,?????????? n lt 8 ,
k lt n ??-1 -1???????? ???n????????????n???,??
??????, . ??????(??????????????????)?
Output ???????,??????,?????????C (????Clt231)?
20
acm1321 ???? Sample Input 2 1 . . 4 4 ...
... ... ... -1 -1 Sample Output 2 1
21
acm1321 ???? ?? ????????,???????????????? ????
???????????????,??????????
22
include ltiostreamgt using namespace std char
Grid99 int n,k int nTotal 0
//???? int anPos9 int nBlankRows 0
int nDoneNum 0 //???????? void Queen(int
nRow) int main() int i,j while( true)
cin gtgt n gtgt k if( n -1 k -1 )
break for( i 0i lt ni ) for( j
0j lt n j ) cin gtgt Gridij nTotal
0 nBlankRows 0 nDoneNum 0 Queen(0)
//??0???? cout ltlt nTotal ltlt endl return
0
23
void Queen(int nRow) if( nRow n nDoneNum
k) //???????n?(???0??),???????????, //
?????,??????1 nTotal return int
i,j for( i -1 i lt n i )
//????????,????-1???????? if( i -1 )
if( nBlankRows lt n - k ) //??????? anPos
nRow -1//??? nBlankRows Queen(
nRow 1 ) //????????,?????????? nBlankRows
--
24
else if( GridnRowi '' ) for(
j 0 j lt nRow j ) if( anPosj i )
//?????? break if( j nRow )
anPosnRow i //?nRow????i nDoneNum
//???????1 Queen(nRow 1
)//???? //????????,?????? //??? nD
oneNum --
25
acm3278 Catch That Cow Farmer John has been
informed of the location of a fugitive cow and
wants to catch her immediately. He starts at a
point N (0 N 100,000) on a number line and
the cow is at a point K (0 K 100,000) on the
same number line. Farmer John has two modes of
transportation walking and teleporting.
Walking FJ can move from any point X to the
points X - 1 or X 1 in a single minute
Teleporting FJ can move from any point X to the
point 2 X in a single minute. If the cow,
unaware of its pursuit, does not move at all, how
long does it take for Farmer John to retrieve it?
26
acm3278 Catch That Cow ?????? ??????,??RLE ?????
,??RLE ?? 1)????? xlt0??? 2)?????????,??????? 3
)??????,??????????,???????? ??????????????????,??
????????,??RLE
27
include ltiostreamgt include ltstringgt include
ltmemorygt using namespace std int n,k struct
SNode int x int nSteps SNode
aQueue3000000 int anRepeated300000 int
nHead,nTail int main() cin gtgt n gtgt
k memset( anRepeated,0,sizeof(anRepeated)) nHe
ad 0 nTail 1 aQueue0.x
n aQueue0.nSteps 0
28
while( nHead ! nTail ) if( aQueuenHead.x
k ) cout ltlt aQueuenHead.nSteps retur
n 0 if ( aQueuenTail.x lt k )
//????????,????????????? aQueuenTail.x
aQueuenHead.x 1 if( anRepeatedaQueuenTai
l.x 0 ) aQueuenTail.nSteps
aQueuenHead.nSteps 1 anRepeatedaQu
euenTail.x 1 nTail if(
aQueuenHead.x - 1 gt 0 ) aQueuenTail.x
aQueuenHead.x - 1 if( anRepeatedaQueuenTai
l.x 0 ) aQueuenTail.nSteps
aQueuenHead.nSteps 1 anRepeatedaQu
euenTail.x 1 nTail if(
aQueuenHead.x 2 - k lt k - aQueuenHead.x )
//?????????? aQueuenTail.x
aQueuenHead.x 2 if( anRepeatedaQueuenTai
l.x 0 ) aQueuenTail.nSteps
aQueuenHead.nSteps 1 anRepeatedaQueuenT
ail.x 1 nTail nHead

29
if( aQueuenHead.x 2 - k lt k -
aQueuenHead.x ) //?????????? aQueuenTai
l.x aQueuenHead.x 2 if(
anRepeatedaQueuenTail.x 0 )
aQueuenTail.nSteps aQueuenHead.nS
teps 1 anRepeatedaQueuenTail.x
1 nTail nHead
Write a Comment
User Comments (0)
About PowerShow.com