东林离散大作业.docxVIP

  • 4
  • 0
  • 约3.9千字
  • 约 9页
  • 2019-09-14 发布于广东
  • 举报
度数序列 Problem:A Time Limit:1000ms Memory Limit:65536K Description 由握手定理我们知道任意的一个图屮,所有顶点的度数之和等于边数的2倍,那么给你一个 无向图的度数序列,你能判定它能否构成无向图吗?(10分) In put 输入数据有多组,每组第一行有1个数为n(l=n=100),接下来第二行有n个正整数,代表 n个度数。 Output 如果能构成图,则在一行内输出yes,否则输出no。 Sample In put 4 1234 Sample Output Yes #include iostream #in cludestdio.h using namespace std; int main() { int n; while(scanf(%d, n) !=-l) { int s = 0; for(int i=0; ivn; i++) { int a; cin?a; s += a; } int b = (sl); if(b == 1) { cout?H notvendl; } else { cout?,,yes,,?e ndl; } 平面图 Problem:B Time Limit:1000ms Memory Limit:65536K Descripti on 已知n阶连通平面图G有r个面,请计算G的边数m. (10分) Input 输入数据有多组,每组有2个正整数n和r,分别代表顶点数和面数。 Output 在一行内输出这个平面图的边数。 Sample In put 76 Sample Output 11 #inelude iostream #inelude stdio.h using namespace std; int main(){ int x, y; while(~scanf(%d%d“, x, y)){ cout?(x+y-2)?e ndl; 树的边数 Problem:C Time Limit:1000ms Memory Limit:65536K Description 设m和t分别是2元正则树t的边数和树叶数,在给定树叶数t的前提下,请你计算边数m? (10 分) Input 输入数据有多组,每组有1个止整数t,代表正则树t的树叶数。 Output 在一行内输出边数m。 Sample In put 10 Sample Output 18 #inelude iostream #inelude stdio.h using namespace std; int main() { int n; while(scanf(“%d“,n) !=-l){ cout?2*(n-l)?endl; } return 0; 错排 Problem:D Time Limit:1000ms Memory Limit:65536K Description 在n个字母的全排列屮,使得每个字母都不在原来位置的排列数是多少?请使用错位排列的 递推公式來计算本题。(10分) Input 输入数据有多组,每组有1个正整数n(lv=代表字母的个数。 Output 在一行内输出这n个字母都不在原来位置的方法数。 Sample In put 2 Sample Output 1 #inelude iostream #inelude stdio.h using namespace std; int D(int x){ if(x == 1){ return 0; } if(x == 2){ return 1; } return (x - l)*(D(x-2) + D(x-1)); } int main() { int n; while(scanf(%dH/ n) !=-l){ cout?D( n)?endl; } 数字编码 Problem:E Time Limit:1000ms Memory Limit:65536K Description 一个编码系统用八进制数字对信息编码,一个码字是有效的当且仅当含有偶数个7,求n位 长的有效码字有多少个? (15分) Input 输入数据有多组,每组有1个止整数n(lv=代表编码的长度。 Output 在一行内输出n位长的有效码字有多少个? Sample In put 1 Sample Output 7 #inelude iostream #inelude stdio.h using namespace std; long a[100]; int f(int n){ if(n 二二 1){ return 7; } return 6*f(n-l)+a[n-l]; } int main() { a[0] = 1; for(int i=l; i20; i++){ a[i]

文档评论(0)

1亿VIP精品文档

相关文档