一步一步模拟,做这种题好累
先放大的的,然后记录剩下的空位有多少,塞1*1和2*2的进去


//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include<cmath> #include<climits> #include<string> #include<map> #include<queue> #include<vector> #include<stack> #include<set> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; #define pb(a) push(a) #define INF 0x1f1f1f1f #define lson idx<<1,l,mid #define rson idx<<1|1,mid+1,r #define PI 3.1415926535898 template<class T> T min(const T& a,const T& b,const T& c) {return min(min(a,b),min(a,c)); } template<class T> T max(const T& a,const T& b,const T& c) {return max(max(a,b),max(a,c)); } void debug() { #ifdef ONLINE_JUDGE #elsefreopen("in.txt","r",stdin);//freopen("d:\\out1.txt","w",stdout); #endif } int getch() {int ch;while((ch=getchar())!=EOF) {if(ch!=' '&&ch!='\n')return ch;}return EOF; } bool run() {int a[7];for(int i=1;i<=6;i++)cin>>a[i];int cnt=0;for(int i=1;i<=6;i++)if(a[i]!=0)cnt=1;if(!cnt)return 0;int res=0;int d1=0,d2=0;res+=a[6];res+=a[5];d1+=a[5]*11;res+=a[4];d2+=a[4]*5;res+=(a[3]+3)/4;if(a[3]%4!=0){d1+=8-a[3]%4;d2+=7-2*(a[3]%4);} // if(a[3]%4==1) // d1+=7,d2+=5; // else if(a[3]%4==2) // d1+=6,d2+=3; // else if(a[3]%4==3) // d1+=5,d2+=1; // 写完发现有规律。。int x;x=min(a[2],d2);a[2]-=x;d2-=x;d1+=d2*4;x=min(a[1],d1);a[1]-=x;d1-=x;res+=(a[2]+8)/9;if(a[2]%9!=0)d1+=(9-a[2]%9)*4;x=min(a[1],d1);a[1]-=x;d1-=x;res+=(a[1]+35)/36;printf("%d\n",res);return true; } int main() {std::ios::sync_with_stdio(false);while(run());return 0; }