- 1、本文档共6页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
第28届宁波市28届中小学生计算机竞赛初中组解题报告.doc
第28届宁波市中小学生计算机程序设计竞赛复赛解题报告(初中组)T1friend
首先求出每个点的度,然后找出目标点,再找出和这个点相邻的点(可以用链表也可以再扫一遍),基数排序一下就好了
var?i,j,n,k,l,m,t,max,max2:longint;a,b,c:array[0..1000011]of?longint;
d:array[1..10011]of?boolean;
begin
??assign(input,friend.in);assign(output,friend.out);reset(input);rewrite(output);
??readln(n,m);for?i:=1?to?m?do?begin?read(a[i],b[i]);inc(c[a[i]]);inc(c[b[i]]);end;
??for?i:=1?to?n?do
??begin
????if?c[i]max?then?begin?max:=c[i];max2:=i;end;//找最大值
??end;
??fillchar(d,?sizeof(d),?false);?
??for?i:=1?to?m?do?if?a[i]=max2?then?d[b[i]]:=true?else?if?b[i]=max2?then?d[a[i]]:=true;//统计和哪些点连通
??for?i:=1?to?n?do?if?d[i]?then?write(i,?);
??close(input);close(output);
end?.
第28届宁波市中小学生计算机程序设计竞赛复赛解题报告(初中组)T2score
首先算出人数最多的学校,方法有3种:
1.暴力模拟并查集,由于数据弱能卡时A掉,如:
1
2
3
4
5
6
7
8
9
for?i:=1?to?n?do?a[i]:=i;
for?i:=1?to?m?do?begin
??read(s,t);
??if?a[s]a[t]?then?begin
????x:=a[t];
????for?j:=1?to?n?do?if?a[j]=x?then?a[j]:=a[s];
??end;
end;
for?i:=1?to?n?do?inc(b[a[i]]);
2.把边存下来然后dfs,不过不属于宁波赛考查范围就不说了
3.并查集维护
然后就是计算分值了,注意到2^0+2^1+…+2^(n-1)=2^n-1,所以用快速幂求一下2^n后100位就行了(其实不用快速幂也行),因为2^n个位≠0,所以直接减一就好
type?p=array[1..311]of?longint;
var?i,j,n,k,l,m,t,max:longint;f,a:array[1..10011]of?longint;
b:p;
function?getf(x:longint):longint;
begin
??if?f[x]=x?then?exit(x);
??f[x]?:=?getf(f[x]);
??exit(f[x]);
end;
procedure?chen(x:longint);//快速幂?
var?c:p;
begin
??fillchar(c,?sizeof(c),?0);if?x=0?then?exit;chen(x?div?2);
??for?i:=1?to?100?do?for?j:=1?to?100?do?inc(c[i+j-1],b[i]*b[j]);
??for?i:=1?to?100?do?begin?inc(c[i+1],c[i]div?10);c[i]:=c[i]mod?10;end;
??b:=c;
??if?x?mod?2?=?1?then
??begin
????for?i:=1?to?100?do?c[i]:=b[i]*2;
????for?i:=1?to?100?do?begin?inc(c[i+1],c[i]div?10);c[i]:=c[i]mod?10;end;
????b:=c;
??end;
end;
procedure?print(x:longint);
var?i:longint;
begin
??b[1]:=1;chen(x);dec(b[1]);i:=1;//计算2^x-1?
??while?b[i]0?do?begin?inc(b[i],10);dec(b[i+1]);inc(i);end;//进位?
??if?x332?then?for?i:=100?downto?1?do?write(b[i])//如果大于100位输出后100位?
??else//否则直接输出?
??begin
????for?i:=100?downto?1?do?if?b[i]0?then?brea
文档评论(0)