题解:P16480 [GKS 2014 #A] Cut Tiles
NoneOfTheAbove · · 题解
link
Solution
首先贪心一下,显然先选大的更优。
所以一种方法就是把
为了满足先选大的的贪心,加入一块的时候要从大到小加,所以当
如果要一个大小为
Code
:::success[code]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef double db;
typedef __int128 i128;
const ll inf=9e18,maxn=501,maxm=32;
const i128 Inf=1e35;
ll t,s[maxn],n,m,cnt[maxm],ans;
void work(ll tc)
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>s[i];
sort(s+1,s+n+1,greater<ll>());
ans=0;
memset(cnt,0,sizeof(cnt));
for(int i=1;i<=n;i++)
{
ll now=s[i];
while(now<=30&&cnt[now]==0) now++;
if(now<=30)
{
cnt[now]--;
for(int j=s[i];j<now;j++) cnt[j]+=3;
}
else
{
ans++;
for(int i=0;i<=30;i++) cnt[i]+=(m>>i)*(m>>i)-4*(i<30?(m>>(i+1))*(m>>(i+1)):0);
cnt[s[i]]--;
}
}
cout<<"Case #"<<tc<<": "<<ans<<"\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
for(int i=1;i<=t;i++) work(i);
}
:::