郑州大学算法设计与分析实验1

发布时间:2024年01月05日

1

#include <bits/stdc++.h>
#define LL long long
 
using namespace std;
const int N = 2e5 + 10;
int t;
LL s[N], b[N];
void solve()
{
	printf("152 = 2 + 5*10 + 1*100");
}

int main()
{
//	freopen("1.in", "r", stdin);
	solve();
	return 0;
}

2

#include <bits/stdc++.h>
#define LL long long
 
using namespace std;
const int N = 2e5 + 10;
int t;
LL s[N], b[N];
void solve()
{
	double x;
	scanf("%lf", &x);
	if(x != 10)	printf("f(%.1f) = %.1f", x, x);
	else
	{
		printf("f(10.0) = 0.1");
	}
}

int main()
{
//	freopen("1.in", "r", stdin);
	solve();
	return 0;
}

3

#include <bits/stdc++.h>
#define LL long long
 
using namespace std;
const int N = 2e5 + 10;
int t;
LL s[N], b[N];
void solve()
{
	int a, b;	scanf("%d%d", &a, &b);
	printf("%d + %d = %d\n", a, b, a + b);
	printf("%d - %d = %d\n", a, b, a - b);
	printf("%d * %d = %d\n", a, b, a * b);
	printf("%d / %d = %d\n", a, b, a / b);
}
int main()
{
//	freopen("1.in", "r", stdin);
	solve();
	return 0;
}

4

#include <bits/stdc++.h> 
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f 
#define x first
#define y second
using namespace std;
using namespace std;
const int N = 2e5 + 10;

double fact(int n)
{
	if(n <= 1)	return 1;
	return fact(n - 1) * n;
}

void solve()
{
	int n, m;
	scanf("%d%d", &m, &n);
	printf("result = %.0f", fact(n) / fact(m) / fact(n - m));	
}

int main()
{
//	freopen("1.in", "r", stdin);
	solve();
	return 0;
}

5

#include <bits/stdc++.h> 
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f 
#define x first
#define y second
using namespace std;
const int N = 2e5 + 10;

void solve()
{
	double v, maxx;
	scanf("%lf%lf", &v, &maxx);
	double dv = v - maxx;
	if(dv / maxx >= 0.5)
	{
//		Exceed 67%. License Revoked	
		cout <<  "Exceed ";
		printf("%.0f", dv / maxx * 100);
		cout << "%. License Revoked";
	}	
	else if(dv / maxx >= 0.1)
	{
//		Exceed 10%. Ticket 200
		cout << "Exceed ";
		printf("%.0f", dv / maxx * 100);
		cout << "%. Ticket 200";
	}
	else	cout << "OK";
}

int main()
{
//	freopen("1.in", "r", stdin);
	solve();
	return 0;
}

6

#include <bits/stdc++.h>
#define LL long long
 
using namespace std;
const int N = 2e5 + 10;

void solve()
{
	int n; scanf("%d", &n);
	double ans = 0, i = 1, j = 2;
	for(int k = 1; k <= n; ++ k)
	{
		ans += j / i;
		double tmp = j;
		j = i + j;
		i = tmp;
	}
	printf("%.2f", ans);
}

int main()
{
//	freopen("1.in", "r", stdin);
	solve();
	return 0;
}

7

#include<stdio.h>
int main(){
  int n,i,m=0;          //m作为计数器,初始化很重要
  int a[10],max;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(i==0) max=a[i];
    else{
      if(a[i]>max){
        max=a[i];
        m=i;
      }
    }
  }
  printf("%d %d",max,m);
  return 0;
}

8

#include <bits/stdc++.h>
#define LL long long
 
using namespace std;
const int N = 2e5 + 10;
int a[20][20], n;

void solve()
{
	scanf("%d", &n);
	for(int i = 1; i<= n; ++ i)
		for(int j = 1; j <= n; ++ j)	
			scanf("%d", &a[i][j]);
	int ans = 0;
	for(int i = 1; i <= n; ++ i)
		for(int j = 1; j <= n; ++ j)
		{
			if(i == n || j == n || (i + j) == n + 1)	continue;
			ans += a[i][j];
		}
		
	printf("%d", ans);
}

int main()
{
//	freopen("1.in", "r", stdin);
	solve();
	return 0;
}

9

#include <bits/stdc++.h> 
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f 
#define x first
#define y second
using namespace std;
struct shu//定义书的结构体
{
    char a[31];//书名
    double  b;//价格
};
int main()
{
  int n,i,max=0,min=0;
    double temp;
    struct shu m[10];//定义数组,元素为10个书的结构体 
    scanf("%d",&n);//书的数量
	getchar();//吸收scanf函数留下的回车
    for(i=0;i<n;i++)//给数组赋值,就是填写书的信息
    {
        gets(m[i].a);//name
        scanf("%lf",&m[i].b);//price
		getchar();//同理吸收回车符
    }
    for(i=1,temp=m[0].b;i<n;i++)//找最贵的
    {
        if(m[i].b>temp)
        { max=i;
        temp=m[i].b;}
    }
    
    for(i=1,temp=m[0].b;i<n;i++)//找最便宜的
    {
        if(m[i].b<temp)
        { min=i;
        temp=m[i].b;}
    }
    printf("%.2lf, %s\n",m[max].b,m[max].a);
     printf("%.2lf, %s",m[min].b,m[min].a);
    return 0;
}

文章来源:https://blog.csdn.net/weixin_61426225/article/details/135397761
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。