《2020百度之星-初赛2》
Car:
思路:暴搜,对于每一个尾数,显然只会在5天中的某一天被禁止。
那么5^10.不会爆
但是如果用字符串cin输入字符串,就会因为输入过慢而TLE,那么这里直接把字符输入变成整形,然后取最后一位即可。
Code:
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef long double ld; typedef pair<int,int> pii; const int N = 1e5+5; const int M = 1e6+6; const LL Mod = 2505; #define pi acos(-1) #define INF 1e8 #define INM INT_MIN #define dbg(ax) cout << "now this num is " << ax << endl; inline int read() { int x = 0,f = 1;char c = getchar(); while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();} return x*f; } int aa[15],cal[15],cnt,n,ans; void dfs(int num,int a,int b,int c,int d,int e) { if(num == cnt+1) { int sum = 0; sum = max(sum,n-a); sum = max(sum,n-b); sum = max(sum,n-c); sum = max(sum,n-d); sum = max(sum,n-e); ans = min(ans,sum); return ; } dfs(num+1,a+cal[num],b,c,d,e); dfs(num+1,a,b+cal[num],c,d,e); dfs(num+1,a,b,c+cal[num],d,e); dfs(num+1,a,b,c,d+cal[num],e); dfs(num+1,a,b,c,d,e+cal[num]); } int main() { int ca;ca = read(); while(ca--) { n = read(); memset(aa,0,sizeof(aa)); for(int i = 1;i <= n;++i) { int x;x = read(); aa[x%10]++; } cnt = 0,ans = INF; for(int i = 0;i <= 9;++i) if(aa[i] != 0) cal[++cnt] = aa[i]; dfs(1,0,0,0,0,0); printf("%d\n",ans); } system("pause"); return 0; }