Snowdream
posts - 403, comments - 310, trackbacks - 0, articles - 7
BlogJava
::
首頁
::
新隨筆
::
聯(lián)系
::
聚合
::
管理
日歷
<
2007年5月
>
日
一
二
三
四
五
六
29
30
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
5
6
7
8
9
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(21)
給我留言
查看公開留言
查看私人留言
隨筆分類
(390)
Algorithm(57)
C/C++(39)
Courses(15)
Economics(2)
Laboratory(25)
Linux(47)
Mathematics(12)
OOP(89)
Scripting(19)
Security(3)
System(28)
Web(10)
書、電影、音樂(11)
其他(14)
點滴(19)
隨筆檔案
(389)
2009年12月 (1)
2009年4月 (1)
2009年3月 (4)
2009年2月 (2)
2009年1月 (2)
2008年11月 (1)
2008年10月 (9)
2008年9月 (1)
2008年7月 (2)
2008年6月 (4)
2008年5月 (12)
2008年4月 (18)
2008年3月 (7)
2008年2月 (33)
2008年1月 (19)
2007年12月 (8)
2007年11月 (14)
2007年10月 (24)
2007年9月 (18)
2007年8月 (28)
2007年7月 (33)
2007年6月 (26)
2007年5月 (30)
2007年4月 (92)
文章檔案
(7)
2007年7月 (2)
2007年5月 (4)
2007年4月 (1)
相冊
Illustration
15ers
jonathan的BLOG
Right There...
宙斯魚的小魚缸
小鮑的世界
簡單幸福
逃遁的Persephone
阿繆爾的錦瑟
風之語的BLOG
友情鏈接
(04CS) ljh
(05CS) 小菜虎的窩
(06CS) FreePeter
(06SS) Overboming
(06SS) Sherry
(06SS) 十指飛揚
(06SS) 銀色子彈
luohandsome的專欄
平淡是真——啃啃不老閣
收藏夾
[ADN.cn]Library
Debian學習筆記
Dictionary of Algorithms and Data Structures
Gollum
Lex&Yacc
Max On Java
techInterview Discussion
核桃仁
程序員面試題精選100題
鐵手
搜索
積分與排名
積分 - 337499
排名 - 167
最新隨筆
1.?新博客
2.?慎用xen的make world...
3.?內存模型相關的資料
4.?安全方面的經(jīng)典論文:A Logic of Authentication
5.?Lock-Free 算法的幾個鏈接
6.?10 Papers Every Programmer Should Read
7.?PieTTY中按Ctrl+S導致掛起的問題解決
8.?Finding and Reproducing Heisenbugs in Concurrent Programs
9.?Ubuntu 8.10 瀏覽網(wǎng)頁不穩(wěn)定的解決方法
10.?[zz]蘇南經(jīng)濟模式興衰親歷記
最新評論
1.?re: C/C++中的序列點
說的太好了,解決我長久的困擾!
--除美滅日平韓
2.?re: 原來GCC是支持尾遞歸的遞推優(yōu)化的
評論內容較長,點擊標題查看
--darkhorse
3.?re: Arch下配置samba服務
我按照你的方法,安裝了SAMBA,但是 /etc/rc.d/samba start 啟動不了samba服務。提示不存在這個文件或目錄的,怎么辦?
--zhangbear
4.?re: [zz]LKM Rootkits on Linux x86 v2.6
rhel 5 系列 安裝了 Xen 內核, 怎么rootkit xen kernel 呢?
--消息
5.?re: CLRS 習題 16.2-6 部分背包問題的O(n)算法
@ynnej
T(n)=2T(n/2)+O(n) 才是 nlgn 注意其中有一個2
--荒廢庭院
閱讀排行榜
1.?[zz]vim+ctags+taglist插件安裝使用(18315)
2.?memcpy函數(shù)代碼分析(9392)
3.?[zz]Zotero與Endnote的互相導入(8784)
4.?BNF 文法 (1) - 語法樹 | 二義性的解決(8272)
5.?Java泛型中的? super T語法(6563)
評論排行榜
1.?C# 學習筆記 (1)(14)
2.?Windows - QQ、網(wǎng)頁Flash視頻無聲音的解決方法(14)
3.?URAL 1011(10)
4.?《編程之美》上的一道題目的討論(8)
5.?Singleton模式與雙檢測鎖定(DCL)(7)
USACO 1.1.4 Arithmetic Progressions
Posted on 2007-05-30 22:18
ZelluX
閱讀(633)
評論(0)
編輯
收藏
所屬分類:
Algorithm
第一次做是用一張hash表記錄的所有的數(shù)是否為所謂的bisquare,然后先枚舉公差,再枚舉首項,本來想這樣做就不用再對結果排序了,沒想到效率很低。
改為先枚舉首項,再枚舉第二項,然后計算公差后,速度提高不少。
另外第一次使用sort方法。
/**/
/*
PROG: ariprog
ID: 06301031
LANG: C++
*/
#include
<
iostream
>
#include
<
fstream
>
#include
<
vector
>
#include
<
algorithm
>
using
namespace
std;
struct
Ans
{
int
start;
int
step;
}
;
bool
compareOp(
const
Ans
&
ans1,
const
Ans
&
ans2);
int
main()
{
ifstream fin(
"
ariprog.in
"
);
ofstream fout(
"
ariprog.out
"
);
int
n, m, i, j, k;
bool
solved
=
false
;
fin
>>
n
>>
m;
//
generate Arithmetic Progressions sequence
bool
seq[
250
*
250
*
2
+
1
];
for
(i
=
0
; i
<=
m
*
m
*
2
; i
++
)
{
seq[i]
=
false
;
}
for
(i
=
0
; i
<=
m; i
++
)
{
for
(
int
j
=
0
; j
<=
i; j
++
)
{
seq[i
*
i
+
j
*
j]
=
true
;
}
}
vector
<
Ans
>
result;
int
step;
for
(i
=
0
; i
<=
m
*
m
*
2
; i
++
)
{
if
(
!
seq[i])
{
continue
;
}
for
(j
=
i
+
1
; j
<=
m
*
m
*
2
; j
++
)
{
if
(
!
seq[j])
{
continue
;
}
step
=
j
-
i;
if
(i
+
step
*
(n
-
1
)
>
m
*
m
*
2
)
{
break
;
}
bool
flag
=
true
;
for
(k
=
1
; k
<
n; k
++
)
{
if
(
!
seq[i
+
step
*
k])
{
flag
=
false
;
break
;
}
}
if
(flag)
{
Ans ans;
ans.start
=
i;
ans.step
=
step;
result.push_back(ans);
solved
=
true
;
}
}
}
if
(
!
solved)
{
fout
<<
"
NONE
"
<<
endl;
}
sort(result.begin(), result.end(), compareOp);
vector
<
Ans
>
::iterator iter;
for
(iter
=
result.begin(); iter
!=
result.end(); iter
++
)
{
fout
<<
iter
->
start
<<
"
"
<<
iter
->
step
<<
endl;
}
fout.close();
return
0
;
}
bool
compareOp(
const
Ans
&
ans1,
const
Ans
&
ans2)
{
return
ans1.step
<
ans2.step;
}
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發(fā)表評論。
網(wǎng)站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
函數(shù)式編程另類指南[zz]
URAL 1011
Sorting Networks
URAL 題解 - wiki
《編程之美》上的一道題目的討論
求n個32位無符號整數(shù)中異或后值最大的兩個數(shù)
SICP 習題記錄 (1)
正則表達式的復雜度
Minesweeper is NP-complete
Tom Duff on Duff's Device
Powered by:
BlogJava
Copyright © ZelluX
51La
主站蜘蛛池模板:
克山县
|
镇平县
|
哈巴河县
|
溧水县
|
淮北市
|
皮山县
|
彭阳县
|
区。
|
灵川县
|
汾西县
|
汨罗市
|
广灵县
|
涡阳县
|
高碑店市
|
衡阳市
|
石河子市
|
许昌市
|
河池市
|
新竹县
|
敖汉旗
|
长治县
|
元氏县
|
吉林市
|
绥棱县
|
上杭县
|
浠水县
|
茂名市
|
齐齐哈尔市
|
双柏县
|
白河县
|
宁远县
|
广水市
|
东港市
|
曲麻莱县
|
简阳市
|
松原市
|
白玉县
|
诸暨市
|
托克托县
|
怀集县
|
同心县
|