Just Arrange the Icons

    科技2024-06-10  72

    Just Arrange the Icons

    题解:单纯的暴力,但需要注意怎么判断可以每个屏幕是s或者s-1个

    #include<bits/stdc++.h> #include<algorithm> #include<iostream> using namespace std; typedef long long ll; typedef long double lf; typedef pair<int,int>P; const int inf = 0x7f7f7f7f; const int N = 2e6+10; const ll mod = 1e9+7; const double PI = 3.14; int read(){ char ch=getchar();int x=0,f=1; while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int random(int n){return(ll)rand()*rand()%n;} int a[N],b[N]; int fun(int s,int n){ int ans = 0; for(int i = 1;i <= n;i++){ int x = b[i]%s; int y = b[i]/s;//满足s的有y个 if(x == 0){//表示没有剩余的 ans += y; }else if(x == s-1 || (s-1-x) <= y){//剩余的正好是s-1或者从前面的y个取出几个可以让第y+1可以成为s-1 ans += (y+1); }else { return -1; } } return ans; } void solve(){ int n = read(),cnt = 0,t = 0; map<int,int>v; for(int i = 1;i <= n;i++){ a[i] = read(); v[a[i]]++; } for(auto it = v.begin();it != v.end();it++){ b[++cnt] = it->second; t = max(t,b[cnt]); } int ans = 2e6+10; for(int i = t;i >= 1;i--){ int p = fun(i,cnt); if(p != -1){ cout<<p<<endl; break; } } } int main(){ //and((unsigned)time(0)); //freopen("out.txt","w",stdout); //freopen("in.txt","r",stdin); int t = read(); while(t--){ solve(); } return 0; }
    Processed: 0.025, SQL: 8