历年ACM

发布时间 : 星期三 文章历年ACM更新完毕开始阅读

h[j].loc=j; }

sort(h,n);

for(j=1;j<=n;j++) {

k=h[j].loc;

while(k!=j)//直到到达位置 {

// cout<

h[k].loc=h[j].loc; h[j].loc=t;

sum+=h[k].value+h[j].value; k=h[j].loc; }

} }

// system(\}

Faulty Odometer 【Description】

You are given a car odometer which displays the miles traveled as an integer. The odometer has a defect, however: it proceeds from the digit 3 to the digit 5, always skipping over the digit 4. This defect shows up in all positions (the one's, the ten's, the hundred's, etc.). For example, if the odometer displays 15339 and the car travels one mile, odometer reading changes to 15350 (instead of 15340). 【Input】

Each line of input contains a positive integer in the range 1..999999 which represents an odometer reading. (Leading zeros will not appear in the input.) The end of input is indicated by a line containing a single 0. You may assume that no odometer reading will contain the digit 4. 【Output】

Each line of input will produce exactly one line of output, which will contain: the odometer reading from the input, a colon, one blank space, and the actual number of miles traveled by the car.

【Sample Input】 15 250 0

【Sample output】

15: 13 250: 198

#include\long n,s,t;

long mishu(long a,int b) { long m=1; if(b==0) { m=1; return m; }

for(int i=1;i<=b;i++) { m=m*a; } return m; }

long travel(long n,int k,long s) { long a,b,count=0; long m1,m2; m1=mishu(10,k); m2=mishu(10,k-1); a=n/m1; b=n%m1; if(k==0) { return s; } else { if(a>0) { count=count+a*m2; //printf(\前%d\\n\ }

if(b>4*m2) { count=count+m2; }

s=s+count; n=n-count; printf(\ travel(n,k-1,s); }

}

void main() { scanf(\ while(n!=0) { s=0; t=n; printf(\ scanf(\ } }

2010年ACM

【试题一】房间安排

2010年上海世界博览会(Expo 2010),是第41届世界博览会。于2010年5月1日至10月31日期间,在中国上海市举行。本次世博会也是由中国举办的首届世界博览会。上海世博会以“城市,让生活更美好”(Better City, Better Life)为主题,将充分探索21世纪城市生活。 这次世博会总投资达450亿人民币,创造了世界博览会史上最大规模记录。吸引200个国家和国际组织参展。预计有7000万人次的参观者。 为了更好地接待在这期间来自世界各地的参观者,如何合理安排各宾馆的住房问题提到了日程。组委会已接到了大量的客房住宿定单,每张定单的内容包括要住宿的房间数,开始住宿时间和要住的天数。为了便于整个城市各宾馆的管理,组委会希望对这些定单进行安排,目的是用尽可能少的房间来满足这些定单,以便空出更多的房间用于安排流动游客。

组委会请求DR. Kong来完成这个任务,对这些定单进行合理安排,使得满足这些定单要求的房间数最少。

假设:某个定单上的游客一旦被安排到某房间,在他预定住宿的期间内是不换房间的。为了简化描述,定单上的开始住宿时间为距离现在的第几天。例如,定单为(10,30,5)表示游客要求使用10个房间,第30天开始连住5天。 【标准输入】

第一行: N 表示定单数

接下来有N行,每行有三个整数 A B C 表示房间数,开始住宿时间和天数 【标准输出】

输出一个整数,为满足所有定单要求的最少房间数。 【约束条件】

1≤N≤10000 1≤A≤10,1≤B≤180, 1≤C≤10 【 样 例 】 标准输入 3 3 10 4 4 9 3 3 12 6 标准输出 7 #include \#include \#include \ #define N 10001 struct book

{ int need; int start; int finish;

}b[N],c[N];//c数组存放当前使用的房间数,及房间的入住时间和离开时间 void sort(int n) {

int i,j;

struct book bk; for(i=1;i

联系合同范文客服:xxxxx#qq.com(#替换为@)