生若有余
A DP Problem poj 2295
WA了N多次,猛然發現一處少寫一符號,總算A掉了.這種題目就是要細心細心再細心.
#include
<
iostream
>
#include
<
cstring
>
#include
<
cmath
>
using
namespace
std;
int
main()
{
char
str[
1000
]
=
{
0
}
;
int
i
=
0
;
int
n
=
0
;
cin
>>
n;
while
(n
--
)
{
int
len
=
0
;
cin
>>
str;
len
=
strlen(str);
int
sign
=
1
;
int
xx[
2
]
=
{
0
}
;
int
cc[
2
]
=
{
0
}
;
int
cnt
=
0
;
//
int
stack
=
0
;
int
empty
=
1
;
for
(i
=
0
;i
<
len;i
++
)
{
switch
(str[i])
{
case
'
=
'
:
if
(
!
empty)
{
cc[cnt]
+=
stack
*
sign;
}
empty
=
1
;
stack
=
0
;
cnt
++
;
sign
=
1
;
break
;
case
'
-
'
:
if
(
!
empty)
{
cc[cnt]
+=
stack
*
sign;
stack
=
0
;
empty
=
1
;
sign
=-
1
;
}
else
sign
*=-
1
;
break
;
case
'
+
'
:
if
(
!
empty)
{
cc[cnt]
+=
stack
*
sign;
stack
=
0
;
sign
=
1
;
empty
=
1
;
}
break
;
case
'
x
'
:
if
(
!
empty)
{
xx[cnt]
+=
stack
*
sign;
stack
=
0
;
empty
=
1
;
}
else
xx[cnt]
+=
sign;
sign
=
1
;
break
;
default
:
stack
=
stack
*
10
+
str[i]
-
'
0
'
;
empty
=
0
;
break
;
}
}
if
(
!
empty)
{
cc[cnt]
+=
sign
*
stack;
}
if
(xx[
0
]
==
xx[
1
])
{
if
(cc[
0
]
==
cc[
1
])
{
cout
<<
"
IDENTITY
"
<<
endl;
}
else
cout
<<
"
IMPOSSIBLE
"
<<
endl;
}
else
if
((cc[
1
]
-
cc[
0
])
%
(xx[
0
]
-
xx[
1
])
==
0
)
{
cout
<<
(cc[
1
]
-
cc[
0
])
/
(xx[
0
]
-
xx[
1
])
<<
endl;
}
else
{
int
flag1,flag2;
if
(cc[
1
]
>
cc[
0
])
flag1
=
1
;
else
flag1
=-
1
;
if
(xx[
0
]
>
xx[
1
])
flag2
=
1
;
else
flag2
=-
1
;
if
(flag1
*
flag2
>
0
)
cout
<<
(cc[
1
]
-
cc[
0
])
/
(xx[
0
]
-
xx[
1
])
<<
endl;
else
cout
<<
(cc[
1
]
-
cc[
0
])
/
(xx[
0
]
-
xx[
1
])
-
1
<<
endl;
}
}
return
0
;
}
posted on 2010-08-21 17:24
若余
閱讀(220)
評論(0)
編輯
收藏
引用
只有注冊用戶
登錄
后才能發表評論。
【推薦】100%開源!大型工業跨平臺軟件C++源碼提供,建模,組態!
網站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
Powered by:
C++博客
Copyright © 若余
導航
首頁
新隨筆
聯系
聚合
管理
<
2010年8月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
統計
隨筆 - 16
文章 - 0
評論 - 4
引用 - 0
常用鏈接
我的隨筆
我的評論
我參與的隨筆
留言簿
給我留言
查看公開留言
查看私人留言
隨筆檔案
(16)
2010年9月 (1)
2010年8月 (14)
2009年8月 (1)
搜索
最新隨筆
1.?poj 1797 Heavy Transportation 最短路
2.?poj 3734 Blocks 生成函數
3.?poj 2348 Euclid's Game 博弈 取子
4.?Poj 2153 Rank List --map / 計數排序
5.?1430 Binary Stirling Numbers 斯特靈數
6.?POJ 3318 Matrix Multiplication 隨機化算法
7.?poj 1195 Mobile phones 二維樹狀數組
8.?POJ 1026 Cipher
9.?Poj 2785 4 Values whose Sum is 0 hash 哈希表
10.?Push Botton Lock poj 3088斯特靈數
最新評論
1.?re: 快速冪取模 PKU ACM 3070
評論內容較長,點擊標題查看
--呢喃的歌聲
2.?re: poj 2085 Inversion 求逆序列[未登錄]
@sdz
謝謝博主,是我理解錯了。
--Klion
3.?re: poj 2085 Inversion 求逆序列
評論內容較長,點擊標題查看
--sdz
4.?re: poj 2085 Inversion 求逆序列[未登錄]
只要知道這樣一個事實:一個序列的逆序唯一決定了這個序列。
樓主,對這個不是很理解,望解釋。
比如
4 5 3 2 1和5 3 4 2 1的逆序數都是9,或許是我理解有問題?
--Klion
評論排行榜
1.?poj 2085 Inversion 求逆序列(3)
2.?快速冪取模 PKU ACM 3070(1)
3.?poj 1631 Bridging signals 最長上升子序列(0)
4.?poj 3358 Period of an Infinite Binary Expansion求有理數循環節長度(0)
5.?poj 2282 The Counting Problem 3252 round numbers(0)
国产精品一区二区久久不卡
|
四虎国产精品免费久久5151
|
亚洲国产精品无码久久九九
|
国产精品99久久久久久人
|
久久精品水蜜桃av综合天堂
|
日本精品久久久久中文字幕
|
狠狠色伊人久久精品综合网
|
国内精品久久国产
|
久久久精品2019免费观看
|
久久国产成人亚洲精品影院
|
久久久久久综合网天天
|
久久精品国产福利国产秒
|
欧美国产成人久久精品
|
日本一区精品久久久久影院
|
伊人久久大香线蕉综合5g
|
成人免费网站久久久
|
亚洲精品乱码久久久久久不卡
|
国产高潮国产高潮久久久
|
久久笫一福利免费导航
|
91精品国产综合久久四虎久久无码一级
|
无码人妻少妇久久中文字幕
|
国产成人无码久久久精品一
|
国产成人精品三上悠亚久久
|
国产精品日韩欧美久久综合
|
亚洲精品无码专区久久久
|
欧美精品一区二区久久
|
国产精自产拍久久久久久蜜
|
77777亚洲午夜久久多喷
|
欧洲精品久久久av无码电影
|
久久亚洲中文字幕精品一区
|
久久亚洲精品无码播放
|
精品久久久久久无码国产
|
66精品综合久久久久久久
|
久久国产精品一国产精品金尊
|
久久婷婷人人澡人人爽人人爱
|
国内精品伊人久久久久影院对白
|
久久国产精品成人免费
|
久久国产精品久久
|
久久美女人爽女人爽
|
91精品国产色综久久
|
久久精品18
|