2021.4.23
A
题意:给一个数n,判断n能否被2050*10^k中取的数相加得到。
题解:每个相加的数都是2050的倍数,所以直接判断n能否被2050整除得到,可以的话直接加上商的位数和。
#include <cstdio>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
ll t,n;
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&n);
if(n%2050)
printf("-1\n");
else
{
ll ans=n/2050;
ll sum=0;
while(ans)
{
sum+=ans%10;
ans/=10;;
}
printf("%lld\n",sum);
}
}
return 0;
}
B
题意:给n+1个点,0到n,每个相邻点的具有m条边,所以共有n组m条边,价值=0到n的最小边的长度,每条边只能被用一次,求这m组方案价值和的最小,求具体的方案。
题解:只需取出所有边的前m小,然后将这前m小的边放在不同的方案数上,这样取得的价值和就是最小的。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdlib.h>
#include <cstring>
#define ll long long
using namespace std;
struct node
{
int x,y,v;
}s[100005];
bool cmp(const node &t1,const node &t2)
{
return t1.v<t2.v;
}
int main()
{
ll t,n,m,a[105][105],b[105][105];
sca