整理出ACM所有题目及答案 - 图文(7)

2020-06-21 15:50

if(fabs(lamda-1.0)

{

double res = (1-pow(lamda, n))/(1-pow(lamda, m+n)); printf(\ } } }

int main() {

int n, m; double p, q;

while(scanf(\ solve(n, m, p, q); }

return 0; }

1213 How Many Tables

Problem Description

Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, and all the friends do not want to stay with strangers.

One important rule for this problem is that if I tell you A knows B, and B knows C, that means A, B, C know each other, so they can stay in one table.

For example: If I tell you A knows B, B knows C, and D knows E, so A, B, C can stay in one table, and D, E have to stay in the other one. So Ignatius needs 2 tables at least.

Input

The input starts with an integer T(1<=T<=25) which indicate the number of test cases. Then T test cases follow. Each test case starts with two integers N and M(1<=N,M<=1000). N indicates the number of friends, the friends are marked from 1 to N. Then M lines follow. Each line consists of two integers A and B(A!=B), that means friend A and friend B know each other. There will be a blank line between two cases.

Output

For each test case, just output how many tables Ignatius needs at least. Do NOT print any blanks.

Sample Input

2 5 3 1 2 2 3 4 5 5 1 2 5

Sample Output

2 4

Author

Ignatius.L

26

Source

杭电ACM省赛集训队选拔赛之热身赛

Recommend

Eddy

代码:#include #define MAX 2000 int n,m;

int start[MAX],end[MAX]; int res;

int arr[MAX]; int len;

int Mempty() {

int i;

for(i=0;i

if(start[i]!=0) return 0; return 1; }

int inSet(int index) {

int i;

for(i=0;i

if(arr[i]==index) return 1; return 0; }

void deal() {

int i;

int space=0; for(i=0;i

if(start[i]==0) space++;

else { start[i-space]=start[i]; }

m=m-space; }

void proc() {

int i; int j;

while(!Mempty()) {

i=0;

while(i

end[i-space]=end[i]; 27

} {

if(start[i]==0) { i++; continue; } if(i==0) {

if(start[i]!=end[i]) { arr[res++]=start[i]; arr[res++]=end[i]; } else arr[res++]=start[i]; start[i]=end[i]=0; } else {

for(j=0;j

if(arr[j]==start[i]) {

if(!inSet(end[i])) arr[res++]=end[i]; start[i]=end[i]=0; i=-1; break; }

if(arr[j]==end[i]) {

if(!inSet(start[i])) arr[res++]=start[i]; start[i]=end[i]=0; i=-1; break; } } } i++; }

len++; deal(); }

if(res==n) len--; else len+=n-res-1; }

int main() {

int i; int num;

scanf(\ while(num--) {

scanf(\

for(i=0;i

28

res=0; len=0; proc(); printf(\ }

return 0; }

1231 最大连续子序列

Problem Description

给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ...,

Nj },其中 1 <= i <= j <= K。最大连续子序列是所有连续子序列中元素和最大的一个, 例如给定序列{ -2, 11, -4, 13, -5, -2 },其最大连续子序列为{ 11, -4, 13 },最大和 为20。

在今年的数据结构考卷中,要求编写程序得到最大和,现在增加一个要求,即还需要输出该 子序列的第一个和最后一个元素。

Input

测试输入包含若干测试用例,每个测试用例占2行,第1行给出正整数K( < 10000 ),第2行给出K个整数,中间用空格分隔。当K为0时,输入结束,该用例不被处理。

Output

对每个测试用例,在1行里输出最大和、最大连续子序列的第一个和最后一个元

素,中间用空格分隔。如果最大连续子序列不唯一,则输出序号i和j最小的那个(如输入样例的第2、3组)。若所有K个元素都是负数,则定义其最大和为0,输出整个序列的首尾元素。

Sample Input

6 -2 11 -4 13 -5 -2 10 -10 1 2 3 4 -5 -23 3 7 -21 6 5 -8 3 2 5 0 1 10 3 -1 -5 -2 3 -1 0 -2 0

Sample Output

20 11 13 10 1 4 10 3 5 10 10 10 0 -1 -2 0 0 0 Hint Hint

Huge input, scanf is recommended.

Source

浙大计算机研究生复试上机考试-2005年

Recommend

JGShining

代码:

#include #include #define MAX 20000 int arr[MAX];

int main()

29

{

int num,temp,i,flage;

int sum,start,end,max=-32768; scanf(\ while(num!=0) {

memset(arr,0,MAX*sizeof(int)); for(i=0;i

scanf(\ sum=0; temp=0;

max=-32768; flage=0;

for(i=0;i

if(arr[i]>=0) flage=1; sum+=arr[i];

if(max

if(flage) printf(\ else printf(\ scanf(\ }

return 0; }

1232 畅通工程

Problem Description

某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府―畅通工程‖的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路?

Input

测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( < 1000 )和道路数目M;随后的M行对应M条道路,每行给出一对正整数,分别是该条道路直接连通的两个城镇的编号。为简单起见,城镇从1到N编号。 注意:两个城市之间可以有多条道路相通,也就是说 3 3 1 2 1 2 2 1

这种输入也是合法的

当N为0时,输入结束,该用例不被处理。

30


整理出ACM所有题目及答案 - 图文(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:SAP HR 薪酬-月中调薪Schema解析

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: