77范文网 - 专业文章范例文档资料分享平台

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

来源:网络收集 时间:2020-06-21 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

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

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库整理出ACM所有题目及答案 - 图文(7)在线全文阅读。

整理出ACM所有题目及答案 - 图文(7).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/jiaoyu/1115829.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: