• Just Arrange the Icons——优雅的暴力


    													J. Just Arrange the Icons
    													time limit per test5 seconds
    													memory limit per test512 megabytes
    													inputstandard input
    													outputstandard output
    

    BerPhone X is almost ready for release with n applications being preinstalled on the phone. A category of an application characterizes a genre or a theme of this application (like “game”, “business”, or “education”). The categories are given as integers between 1 and n, inclusive; the i-th application has category ci.

    You can choose m — the number of screens and s — the size of each screen. You need to fit all n icons of the applications (one icon representing one application) meeting the following requirements:

    On each screen, all the icons must belong to applications of the same category (but different screens can contain icons of applications of the same category);
    Each screen must be either completely filled with icons (the number of icons on the screen is equal to s) or almost filled with icons (the number of icons is equal to s−1).
    Your task is to find the minimal possible number of screens m.

    Input
    The first line contains an integer t (1≤t≤10000) — the number of test cases in the input. Then t test cases follow.

    The first line of each test case contains an integer n (1≤n≤2⋅106) — the number of the icons. The second line contains n integers c1,c2,…,cn (1≤ci≤n), where ci is the category of the i-th application.

    It is guaranteed that the sum of the values of n for all test cases in the input does not exceed 2⋅106.

    Output
    Print t integers — the answers to the given test cases in the order they follow in the input. The answer to a test case is an integer m — the minimum number of screens on which all n icons can be placed satisfying the given requirements.

    Example
    input 1

    3
    11
    1 5 1 5 1 5 1 1 1 1 5
    6
    1 2 2 2 2 1
    5
    4 3 3 1 2
    

    output 1

    3
    3
    4
    

    Note
    In the first test case of the example, all the icons can be placed on three screens of size 4: a screen with 4 icons of the category 1, a screen with 3 icons of the category 1, and a screen with 4 icons of the category 5.

    题目大意:
    给出 n 个数,表示这 n 个图标的类型,可以自己安排屏幕的大小尺寸(能够放图标的个数),然后问能够最少需要几个屏幕;
    条件是:1. 不同一个屏幕只能是放一种类型的图标,但是同一种类型的图标可以放进不同的屏幕
    2. 放的时候只能是放满或者是只空一个位置

    方法:优雅的进行暴力就完了,注意统计数量的时候,不要用map,会被卡内存的(CF不会卡)
    详尽的可以参考这篇博客第22条

    Code:

    ll mp[maxn];
    vector <ll>vet;
    ll val(ll size, ll cnt) {
    	///屏幕大小和这一种一共的数量
    	ll t1 = (cnt + size - 1) / size;
    	/// 类似上取整比如大小为4,但是刚好有5个,这时候就不得不占用两个屏幕
    	ll t2 = 0x3f3f3f3f;
    	if (size > 1) {
    		t2 = cnt / (size - 1);///最大的需要数量
    		//因为每一屏幕可以放size - 1个
    	}
    	if (t1 <= t2) return t1;
    	else return 0x3f3f3f3f;
    }
    int main()
    {
    	int T = read;
    	while (T--) {
    		ll n = read;
    		ll ans = 0x3f3f3f3f;
    		vet.clear();///每次都要清空
    		for (ll i = 1; i <= n; i++) {
    			ll x = read;
    			mp[x]++;
    		}
    		for (ll i = 1; i <= n; i++) {
    			if (mp[i]) {///只要是有
    				vet.push_back(mp[i]);
    				mp[i] = 0;
    			}
    		}
    		sort(vet.begin(), vet.end());
    		ll SZ = vet.size();
    		ll lim = vet[0] + 1;
    		for (ll i = 1; i <= lim; i++) {///最少的个数 +1 屏幕的大小
    			ll sum = 0;
    			for (ll j = 0; j < SZ; j++)
    			{
    				sum += val(i, vet[j]);
    			}
    			ans = min(ans, sum);///每次统计最小
    		}
    		printf("%lld
    ", ans);
    	}
    
    	return 0;
    }
    
  • 相关阅读:
    JB开发之二 [jailbreak,越狱开发研究]
    iOS9 Https技术预研
    Tweak和app交互方案【进程通信】
    iOS设备抓包终极解决方案(支持https)
    Anti-Anti dylib(反 反-dylib钩子(Anti-tweak))
    Hook ptrace 调试加入了ptrace函数的程序
    How do I determine if I'm being run under the debugger?
    个人整理的一些iOS Entitlements
    SQLite在多线程环境下的应用
    别的程序员是怎么读你的简历的
  • 原文地址:https://www.cnblogs.com/PushyTao/p/14507431.html
Copyright © 2020-2023  润新知