2020中南大学研究生招生夏令营机试题
  R9zn05DADVjm 2023年11月02日 42 0



title: 2020中南大学研究生招生夏令营机试题
date: 2020-05-07 17:34:23
categories: 算法
tags: [C++, 思维]
mathjax: true


题目编号

标题

来源/分类

正确

提交

Y

1252

缺失的彩虹

2020中南大学研究生招生夏令营机试题

136

334

Y

1253

最小价值和

2020中南大学研究生招生夏令营机试题

201

645

Y

1254

PIPI上学路

2020中南大学研究生招生夏令营机试题

121

583

Y

1255

最大容量和

2020中南大学研究生招生夏令营机试题

173

592

Y

1256

最小特征值之和

2020中南大学研究生招生夏令营机试题

32

55

1252: 缺失的彩虹

时间限制: 1 Sec 内存限制: 128 MB
提交: 334 解决: 136
[提交] [状态] [讨论版] [命题人:test]

题目描述

众所周知,彩虹有7种颜色,我们给定七个 字母和颜色 的映射,如下所示:
‘A’ -> “red”
‘B’ -> “orange”
‘C’ -> “yellow”
‘D’ -> “green”
‘E’ -> “cyan”
‘F’ -> “blue”
‘G’ -> “purple”
但是在某一天,彩虹的颜色少了几种,你能告诉PIPI哪些彩虹的颜色没有出现过吗?

输入

输入包含多组测试用例。
对于每组测试用例,输入n个合法的颜色字符串(0<=n<=100),输出有多少种颜色没有出现过,并分别输出对应的字母。

输出

对于每一组测试样例,输出一个数字,代表缺失的颜色种数,然后按照升序输出缺失颜色对应的字母。

样例输入
3
red
orange
cyan
样例输出
4 
C
D
F
G
来源/分类

2020中南大学研究生招生夏令营机试题

解析:

签到

#include<iostream>
#include<cstring>
#include<map>
using namespace std;
string a[]= {"red","orange","yellow","green","cyan","blue","purple"} ;
char b[]= {'A','B','C','D','E','F','G'};
int main()
{

    int n;

    while(~scanf("%d",&n))
    {
    	map<string,int> mp;
        string s;
        for(int i=1; i<=n; i++)
        {
            cin>>s;
            mp[s]=1;
        }
        char ans[10];
        int tot=0;
        for(int i=0; i<7; i++)
        {
            if(mp[a[i]]==0)
			{
				ans[tot++]=b[i];
			}
        }
        printf("%d\n",tot);
        for(int i=0;i<tot;i++)
		{
			printf("%c\n",ans[i]);
		}

}



return 0;
}

1253: 最小价值和

时间限制: 1 Sec 内存限制: 128 MB
提交: 645 解决: 201
[提交] [状态] [讨论版] [命题人:test]

题目描述

给定 n 个整数对(ai, bi) , 每个整数对的价值是(i-1)*ai + (n-i)*bi (下标从1开始, 这里的 ai 、bi 和输入不一定对应),然后问所有整数对的最小价值总和。

输入

输入包含多组测试用例。
对于每组测试用例,首先输入数对的数量n(n<=1e5)
接下来输入n对数对 ai bi (0<=ai,bi<=1e9)

输出

对于每组测试用例,输出这些整数对的最小价值总和。

样例输入
3
3 2
2 4
6 1
样例输出
11
提示

0 * 6 + 2 * 1 + 1 * 3 + 1 * 2 + 2 * 2 + 0 * 4 = 11

来源/分类

2020中南大学研究生招生夏令营机试题

解析

2020中南大学研究生招生夏令营机试题_#include

#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=100005;
struct Node
{
    LL a,b;
} x[N];
bool cmp1(Node u,Node v)
{
	return u.a-u.b>v.a-v.b;
}

int main()
{

    int n;

    while(~scanf("%d",&n))
    {

        for(int i=1; i<=n; i++)
        {
            scanf("%lld%lld",&x[i].a,&x[i].b);
        }
        sort(x+1,x+n+1,cmp1);
        LL ans1=0;
        for(int i=1;i<=n;i++)
		{
			ans1+=(i-1)*x[i].a+(n-i)*x[i].b;
		}
		
     
		printf("%lld\n",ans1);

    }



    return 0;
}

1254: PIPI

上学路时间限制: 1 Sec 内存限制: 128 MB
提交: 583 解决: 121
[提交] [状态] [讨论版] [命题人:test]

题目描述

PIPI每天早上都要从CSU的某个位置走到另一个位置。CSU可以抽象为一个n*m的方格。PIPI每天都要从(x1,y1)走到(x2,y2),规定每次可以向下或者向右移动一格。总共有q次询问,每次询问从(x1,y1)走到(x2,y2)有多少条不同的路径,答案对1000000007取模。

输入

输入包含多组测试用例。
对于每组测试用例,首先输入三个整数n,m,q(1<=n,m,q<=5000),代表方格的大小和询问次数。
接下来q行,每行输入四个正整数 x1, y1 ,x2,y2(1<=x1<=x2<=n ,1<=y1<=y2<=m) 。意义如题所示。

输出

4 4 4
1 1 1 1
1 1 2 2
1 1 1 2
1 1 2 1

样例输入
1
2
1
1
来源/分类

2020中南大学研究生招生夏令营机试题

解析:

建议纯暴力,其实也就组合数

#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=50005;
const LL mod=1000000007;
LL fact[N+5],infact[N+5];

LL qmi(LL a, LL k, LL p)   
{
    LL res = 1;
    while (k)
    {
        if (k & 1)
            res = (LL)res * a % p;
        a = (LL)a * a % p;
        k >>= 1;
    }
    return res;
}
LL C(int a,int b)
{
	return fact[a]*(infact[b]*infact[a-b]%mod)%mod;
}


int n,m,q;
int main()
{
    
    fact[0] = infact[0] = 1;
    for (int i = 1; i < N; i ++ )
    {
        fact[i] = (LL)fact[i - 1] * i % mod;
        infact[i] = (LL)infact[i - 1] * qmi(i, mod - 2, mod) % mod;
    }

    while(~scanf("%d%d%d",&n,&m,&q))
    {
        int x1,x2,y1,y2;
        for(int i=1; i<=q; i++)
        {
            scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
            int a=x2-x1;
            int b=y2-y1;
            printf("%lld\n",C(a+b,a)%mod);

        }
    }



    return 0;
}
#include "bits/stdc++.h"
using namespace std;

const int maxn = 5e3+7;
const int mod = 1e9+7;

int ways[maxn][maxn];

int main() {
    ways[1][0]=1; 
    for(int i=1; i<maxn; ++i) {
        for(int j=1; j<maxn; ++j) {
            ways[i][j]=(ways[i-1][j]+ways[i][j-1])%mod;
        }
    }
    int n, m, q;
    ios::sync_with_stdio(false); cin.tie(0); 
    while(cin>>n>>m>>q) {
        while(q--) {
            int x1, y1, x2, y2;
            cin>>x1>>y1>>x2>>y2;
            cout<<ways[x2-x1+1][y2-y1+1]<<'\n'; 
        }
    }
}

1255: 最大容量和

时间限制: 1 Sec 内存限制: 128 MB
提交: 593 解决: 174
[提交] [状态] [讨论版] [命题人:test]

题目描述

有 m 根木棍,m = n * k,n 个桶,每个桶由 k 块木板构成,桶的容量由最短的木板长度决定,桶的底面积为 1,现要求任意两个桶间的容量差小于等于 L,问 n 个桶的最大容量和。
如果无法满足组成n个桶,输出0.

输入

第一行输入三个整数 n,k, L(nk<=1e5)。
第二行输入n
k根木板长度,a1,a2,a3…1 ≤ a**i ≤ 10^9

输出

输出n个木桶最大容量和。

样例输入

4 2 1
2 2 1 2 3 2 2 3

样例输出

7

提示

这四个桶可以是1 2, 2 2, 2 3, 2 3,那么答案就是1+2+2+2 = 7。

来源/分类

2020中南大学研究生招生夏令营机试题

我们仍然只需要从大到小选择木棍,要从不大于 amin+L 的地方开始构建桶即可

#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=100005;
int n,k,l;
int a[N];
int two_find(int l,int r,int val)
{
	while(l<r)
	{
		int mid=(l+r+1)>>1;
		if(a[mid]<=val)
		{
			l=mid;
		}
		else
			r=mid-1;
	}
	return l;
}
int main()
{
    while(~scanf("%d%d%d",&n,&k,&l))
    {
        for(int i=1;i<=n*k;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a+1,a+n*k+1);
		
		LL ans=0;
		
		if(a[n]-a[1]>l)  
		{
			printf("0\n");
			continue;
		}
		int pos=two_find(1,n*k,a[1]+l);
		//cout<<pos<<endl;
		if(a[pos]<=a[1]+l)
		{
			int num=n*k-pos;
			for(int i=pos;i>=1;i--)
			{
				//cout<<num<<endl;
				num+=1;
				if(num>=k)
				{
					ans+=a[i];
					num-=k;
				}
			
			}
		}
		
			 
			
		printf("%lld\n",ans);
    }
    return 0;
}


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  uvM09mQNI0hF   2023年11月19日   27   0   0 sedshell字符串
  38gcbVXUBcLA   2023年11月19日   25   0   0 字符串python拼接字符串
  vxoexqgjyiCS   2023年11月19日   17   0   0 i++linuxvim
  vxoexqgjyiCS   2023年11月19日   20   0   0 linux字符串最大匹配
  vxoexqgjyiCS   2023年11月19日   24   0   0 服务器vim字符串