lisan

//度数序列
//Problem:
//A
//Time Limit:1000ms
//Memory Limit:65536K
//Description
//由握手定理我们知道任意的一个图中, 所有顶点的度数之和等于边数的 2 倍, 那么给你一个
//无向图的度数序列, 你能判定它能否构成无向图吗? (10 分)
//Input
//输入数据有多组, 每组第一行有 1 个数为 n(1<=n<=100), 接下来第二行有 n 个正整数, 代表
//n 个度数。
//Output
//如果能构成图, 则在一行内输出 yes, 否则输出 no。
//Sample Input
//4
//1 2 3 4
//Sample Output
//Yes

#include
#include <stdio.h>
using namespace std;
int main()
{
int n;
while(scanf("%d", &n) !=-1)
{
int s = 0;
for(int i=0; i<n; i++)
{
int a;
cin>>a;
s += a;
}
int b = (s&1);
if(b == 1)
{
cout<<“no”<<endl;
}
else
{
cout<<“yes”<<endl;
}
}
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
while(~scanf("%d",&n))
{
int sum=0,n2=n*(n-1),in;
while(n–)
scanf("%d",&in),sum+=in;
((sum&1)&&(n2<sum))?printf(“no\n”):printf(“yes\n”);
}
return 0;
}

//平面图
//Problem:
//B
//Time Limit:1000ms
//Memory Limit:65536K
//Description
//已知 n 阶连通平面图 G 有 r 个面, 请计算 G 的边数 m.(10 分)
//Input
//输入数据有多组, 每组有 2 个正整数 n 和 r,分别代表顶点数和面数。
//Output
//在一行内输出这个平面图的边数。
//Sample Input
//7 6
//Sample Output
//11
#include
#include <stdio.h>
using namespace std;
int main()
{
int x, y;
while(~scanf("%d%d", &x, &y))
{
cout<<(x+y-2)<<endl;
}
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
int x,y;
while(~scanf("%d%d",&x,&y))
printf("%d\n",x+y-2);
return 0;
}
//树的边数
//Problem:
//C
//Time Limit:1000ms
//Memory Limit:65536K
//Description
//设 m 和 t 分别是 2 元正则树 t 的边数和树叶数, 在给定树叶数 t 的前提下, 请你计算边数 m?
//(10 分)
//Input
//输入数据有多组, 每组有 1 个正整数 t,代表正则树 t 的树叶数。
//Output
//在一行内输出边数 m。
//Sample Input
//10
//Sample Output
//18
#include
#include <stdio.h>
using namespace std;
int main()
{
int n;
while(scanf("%d", &n) !=-1)
{
cout<<2*(n-1)<<endl;
}
return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
int n;
while(~scanf("%d",&n))
printf("%d\n",2*(n-1));
return 0;
}

//错排
//Problem:
//D
//Time Limit:1000ms
//Memory Limit:65536K
//Description
//在 n 个字母的全排列中, 使得每个字母都不在原来位置的排列数是多少? 请使用错位排列的
//递推公式来计算本题。 (10 分)
//Input
//输入数据有多组, 每组有 1 个正整数 n(1<=n<=10),代表字母的个数。
//Output
//在一行内输出这 n 个字母都不在原来位置的方法数。
//Sample Input
//2
//Sample Output
//1
#include
#include <stdio.h>
using namespace std;
int D(int x)
{
if(x == 1)
{
return 0;
}
if(x == 2)
{
return 1;
}
return (x - 1)(D(x-2) + D(x -1));
}
int main()
{
int n;
while(scanf("%d", &n) !=-1)
{
cout<<D(n)<<endl;
}
return 0;
}
数字编码
Problem:
E
Time Limit:1000ms
Memory Limit:65536K
Description
一个编码系统用八进制数字对信息编码, 一个码字是有效的当且仅当含有偶数个 7, 求 n 位
长的有效码字有多少个? (15 分)
Input
输入数据有多组, 每组有 1 个正整数 n(1<=n<=10),代表编码的长度。
Output
在一行内输出 n 位长的有效码字有多少个?
Sample Input
1
Sample Output
7
#include
#include <stdio.h>
using namespace std;
long a[100];
int f(int n)
{
if(n == 1)
{
return 7;
}
return 6f(n-1)+a[n-1];
}
int main()
{
a[0] = 1;
for(int i=1; i<20; i++)
{
a[i] = a[i-1]8;
}
int n;
while(scanf("%d", &n)!=-1)
{
cout<<f(n)<<endl;
}
return 0;
}
方格涂色
Problem:
F
Time Limit:1000ms
Memory Limit:65536K
Description
一个 1n 的方格用红、 蓝、 绿或橙色四种颜色涂色, 如果有偶数个方格被涂成红色, 还有偶
数个方格被涂成绿色, 问有多少种方案? (15 分)
Input
输入数据有多组, 每组有 1 个正整数 n(1<=n<=10),代表方格的个数。
Output
在一行内输出有多少种方案?
Sample Input
1
Sample Output
2
#include
#include <stdio.h>
using namespace std;
long a[100];
long b[100];
int main()
{
a[0] = 1;
b[0] = 1;
for(int i=1; i<20; i++)
{
a[i] = a[i-1] * 2;
}
int n;
while(scanf("%d", &n)!=-1)
{
if(n == 0)
{
cout<<1<<endl;
continue;
}
cout<<a[2n-2]+a[n-1]<<endl;
}
return 0;
}
最大公约数-离散数学
Problem:
G
Time Limit:1000ms
Memory Limit:65536K
Description
已知用辗转相除法可以计算 2 个数的最大公约数, 2 个数互素的条件是这 2 个数的最大公因
子是 1, 现在的问题是让你判断 2 个数是否是互素的? (15 分)
Input
输入数据有多组, 每组有 2 个正整数 a,b(1<=a,b<=1000000)
Output
如果这 2 个数互素, 在一行内输出 yes, 否则输出 no.
Sample Input
10 11
10 16
Sample Output
yes
No
#include
#include <stdio.h>
using namespace std;
int main()
{
int n, m;
while(scanf("%d%d", &n, &m) !=-1)
{
bool flag = true;
if(m < n)
{
swap(m,n);
}
for(int i=2; i<=n; i++)
{
if(m%i == 0 && n%i == 0)
{
flag = false;
break;
}
}
if(flag == false)
{
cout<<“no”<<endl;
}
else
{
cout<<“yes”<<endl;
}
}
return 0;
}
中国剩余定理
Problem:
H
Time Limit:1000ms
Memory Limit:65535K
Description
根据孙子算经, 里面有一个物不知数的问题, 现在孙子的问题是: 今有物, 不知其数, m1
数之剩 a1;
m2 数之剩 a2;
m3 数之剩 a3; 请用中古剩余定理求解该数是多少, 本题要求最小
的正整数解?
Input
输入数据有多组, 每组一行, 每行 6 个整数, 分别为 a1,m1,a2,m2,a3,m3;
这里 m1,m2,m3 是
两两互素的!
Output
对于每组数据, 请计算该问题的最小正整数解?
Sample Input
2 3 3 5 2 7
Sample Output
23
#include
#include <stdio.h>
using namespace std;
int findM_(int M, int m)
{
for(int i =0; i<100; i++)
{
if((Mi-1)%m == 0)
{
return i;
}
}
}
int main()
{
int a1, a2, a3;
int m1, m2, m3;
while(~scanf("%d%d%d%d%d%d", &a1, &m1, &a2, &m2, &a3, &m3))
{
int M1 = m2m3;
int M2 = m1m3;
int M3 = m2m1;
int M12 = findM_(M1,m1);
int M22 = findM_(M2, m2);
int M32 = findM_(M3, m3);
int x = (a1M1M12 + a2M2M22 + a3M3M32)%(m1m2*m3);
cout<<x<<endl;
}
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值