2020牛客暑期多校训练营(第九场)解题报告(正在更新)

A:Groundhog and 2-Power Representation

题目链接
题意:
朴素的递归思想,模拟从里到外去括号的过程。
这里我用的是PythonAC的

def x(a):
	return 2**a

str = input()
str = str.replace("2(","x(")
print(eval(str))

I:The Crime-solving Plan of Groundhog

题目链接
题意: 给出n个1-9之间的数字,组成两个正整数(不含前导零)求出乘积的最小值。
思路:

  • 只有在一个数字乘上一个大数的时候乘积最小。所以只需要把数字排序,找到一个最小的非零数,再将其他的数字组成一个最小的正整数。最后进行大数乘法。
  • 我用的是vis数组来标记这个数字是否被挑选过。
    下面是AC代码:
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)	
#define T int t ;cin >> t;while(t--)
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
inline ll gcd(ll a,ll b){return b == 0? a:gcd(b, a % b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll Mode(ll a, ll b, ll mode)    {ll sum = 1;if(mode == 1)return 0 ;while (b) {if (b & 1) {sum = (sum * a) % mode;b--;}b /= 2;a = a * a % mode;}return sum;}
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-11;
const ll mod = 1e9 + 7;
inline long long read(){
long long x=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-f;ch=getchar();}
while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=getchar();
return x *f;
}
string Multiply(string s,int x)  //大数乘以整形数
{
    reverse(s.begin(),s.end());
    int cmp=0;
    for(int i=0;i<s.size();i++)
    {
        cmp=(s[i]-'0')*x+cmp;
        s[i]=(cmp%10+'0');
        cmp/=10;
    }
    while(cmp)
    {
        s+=(cmp%10+'0');
        cmp/=10;
    }
    reverse(s.begin(),s.end());
    return s;
}
int a[maxn];
char b[5],c[maxn];
bool vis[maxn];
int main()
{
	T{
		memset(vis,0,sizeof(vis)) ;
		memset(c,0,sizeof(c)) ;
		int n;
		scanf("%lld",&n) ;
		for(int i = 0 ; i < n ; i++) scanf("%lld",&a[i]) ;
		sort(a,a+n) ;
		bool f = 0 ;
		for(int i = 0 ; i < n ; i++){
			if(a[i]!= 0&&f == 0){
				b[0] = a[i] + '0' ;
				vis[i] = 1 ;
				f = 1 ;
			}
			else if(a[i]!= 0&& f){
				c[0] = a[i] + '0' ;
				vis[i] = 1 ;
				break ;
			}
		}
		int cnt = 1 ;
		for(int i = 0 ; i < n ; i++){
			if(vis[i] == 0)
			{
				vis[i] = 1 ;
				c[cnt] = a[i] + '0';
				cnt++ ;
			}
		}
		string s = c ;
		int x = b[0] - '0' ;	
		cout << Multiply(s,x)<< endl ;
	}
	return 0;
}

F: Groundhog Looking Dowdy

题目链接
题意:让我们选出M天的最小差值的穿搭方式
思路:对每一组的数字进行排序,将最小值提出。再对所有最小值排序即可。
下面是AC代码:

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)	
#define T int t ;cin >> t;while(t--)
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
inline ll gcd(ll a,ll b){return b == 0? a:gcd(b, a % b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll Mode(ll a, ll b, ll mode)    {ll sum = 1;if(mode == 1)return 0 ;while (b) {if (b & 1) {sum = (sum * a) % mode;b--;}b /= 2;a = a * a % mode;}return sum;}
const int maxn = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-11;
const ll mod = 1e9 + 7;
ll b[maxn] ;
ll a[maxn] ;
int main()
{
	ll n , m  ;
	scanf("%lld%lld",&n,&m) ;
	for(int i = 0 ; i < n ; i++){
		ll  k  ;
		scanf("%lld",&k) ;
		for(int j = 0 ; j < k ; j++)
			scanf("%lld",&b[j]) ;
		sort(b,b+k) ;
		a[i] = b[0] ;
	}
	sort(a,a+n) ;
	printf("%lld\n",a[m-1] - a[0]) ;
	return 0 ;
}

猜你喜欢

转载自blog.csdn.net/zcmuhc/article/details/107889483