SDUT 2021 Spring Individual Contest(for 20) - 1补题
Posted 如风如影�
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SDUT 2021 Spring Individual Contest(for 20) - 1补题相关的知识,希望对你有一定的参考价值。
C - Cheap Kangaroo
题目链接: link.
原题再现:
There are N kangaroos going out to eat at an Indian restaurant. The ith kangaroo wants to eat exactly xi food. The kangaroos all want to order the same size of plates, but each one can order more than one plate for themselves if they need to. If the kangaroo orders more than he needs, he can simply hide the leftovers in his pouch.
At this Indian restaurant, the cost of the plate is the same as its size. Since Karl the Kangaroo is paying and is low on money, he wants to know what is the minimum cost to feed all N kangaroos and what is the largest possible size of the plates that satisfies this minimum cost?
The first line of input is T – the number of test cases.
The first line of each test case is an integer N (1 ≤ N ≤ 105).
The second line contains N space-separated integers xi (1 ≤ xi ≤ 109).
For each test case, output a line containing two space-separated integers – the minimum cost and the maximum plate size that corresponds to when the total cost is minimized.
题目就是求多个数的最大公约数(gcd)
gcd板子需要记住并且会用(辗转相除法)
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
if(b==0) return a;
else return gcd(b,a%b);
int main()
int t;
scanf("%d",&t);
while(t--)
int n;
scanf("%d",&n);
long long sum=0;
int d,f,c;
scanf("%d",&d);
f=d;
sum=d;
for(int i=1;i<n;i++)
scanf("%d",&d);
sum=sum+d;
f=gcd(d,f);
cout<<sum<<' '<<f<<endl;
return 0;
以上是关于SDUT 2021 Spring Individual Contest(for 20) - 1补题的主要内容,如果未能解决你的问题,请参考以下文章
SDUT 2021 Spring Individual Contest(for 20) - 1补题
SDUT 2021 Spring Individual Contest(for 20) - 17(补题)
SDUT 2021 Spring Individual Contest(for 20) - 15(补题)
SDUT 2021 Summer Individual Contest - 2(for 20)(补题)
SDUT 2021 Winter Individual Contest - N(B-Derangement)
2021-08-03SDUT 2021 Summer Individual Contest - 4(for 20)(补题)