第一次笔试

来源:互联网 发布:叶公好龙知乎 编辑:程序博客网 时间:2024/05/21 12:08
#include<iostream>#include<list>using namespace std;int main(){int Case;scanf("%d",&Case);    list<int>font;for(int i=0;i<Case;i++){int N,P,W,H;list<int>PChar;    list<int>::iterator itor;scanf("%d%d%d%d",&N,&P,&W,&H);for(int i=0;i<N;i++){int Para;scanf("%d",&Para);PChar.push_back(Para);}int SUM=0;itor=PChar.begin();while(itor!=PChar.end()){SUM+=*itor++;}int Per=SUM/P;int M;if(W>=H){M=H;}else M=W;for(int i=M;i>0;i--){if((W/i)*(H/i)<=Per){int PerLine=W/i;int TotalLine=(H/i)*P;int ActualLine=0;list<int>::iterator Line;Line=PChar.begin();while(Line!=PChar.end()){int x=(*Line)/PerLine;if((*Line)*1.0/PerLine>x)x+=1;Line++;ActualLine+=x;}if(TotalLine>=ActualLine){font.push_back(i);break;}}}while(!PChar.empty())       {   PChar.pop_front();       }}list<int>::iterator ifont;ifont=font.begin();while(ifont!=font.end()){printf("%d\n",*ifont++);}system("pause");return 0;}
以上是今晚参加的微软4月份笔试题目,不仅看到了自己的基础薄弱,方法论也有问题。跌倒在此刻我心服口服,但多少还有些不甘,明明用vs2010编译的是成功的啊。

0 0