1 条题解
-
0oistream (oistream) LV 8 MOD @ 2020-08-13 18:29:17
用两个变量分别记录当前行的行高和摆放起始位置,线性时间逐行模拟每一行,然后利用公式
\[\text{当前行块数}=\lfloor\dfrac{\text{墙宽}-\text{当前行摆放起始位置}}{\text{砖宽}}\rfloor\]
计算出当前行块数。然后有
\[\text{总占用面积}=\sum_{\text{每一行}}{\text{当前行块数}\times \text{砖长}\times \text{砖宽}}\]
墙面积减去它即为所求。
Code: \(\sout\text{忍住不压行很难吗?——很难。}\)
#include <iostream> #include <cstdio> #include <vector> #include <cmath> using namespace std; typedef long long Num; typedef unsigned long long Unum; typedef long double Lfloat; #define Rint register int #define It iterator #define Os ostream #define Is istream #define Ifs ifstream #define Ofs ofstream #define AK_IOI bfw template<typename T>/*T: integer type*/ void read(T& num) { char ch;int f;num=0;while(1){ch=getchar();if(ch=='-' || (ch>='0'&&ch<='9')) break;} (ch=='-')?(f=-1):(f=1,num+=ch-'0');while(1){ch=getchar();if(!(ch=='-' || (ch>='0'&&ch<='9'))) break; num*=10;num+=ch-'0';} num*=f; } struct Square { double len; double hei; Square():len{0.0},hei{0.0}{ } Square(const double &length,const double &height):len{length},hei{height}{ } inline double length() const{return len;} inline double height() const{return hei;} inline double s() const{return len*hei;} }; inline int calc(const double &offset,const Square &panel,const Square &wall) { double offs=offset; offs-=panel.length()/2.0; return floor((wall.length()-offs)/panel.length()); } int main() { /*Init*/ double wallL,wallH,panelL,panelH; cin>>wallL>>wallH>>panelL>>panelH; Square wall{wallL,wallH},panel{panelL,panelH}; /*StdHeight*/ double lHeight=wall.hei/2.0; double lOffset=panel.len/2.0; int cnt=calc(lOffset,panel,wall); /*Down*/ while(1) { lHeight+=panel.hei; lOffset+=panel.len/4.0; if(lHeight+panel.hei/2.0>wall.hei) { break; } else if(lOffset+panel.len/2.0>wall.len) { break; } cnt+=calc(lOffset,panel,wall); cout<<lHeight<<" "<<lOffset<<" "<<cnt<<endl; } /*Up*/ lHeight=wall.hei/2.0; lOffset=panel.len/2.0; while(1) { lHeight-=panel.hei; lOffset+=panel.len/2.0; if(lHeight-panel.hei/2.0<0.0) { break; } else if(lOffset+panel.len/2.0>wall.len) { break; } cnt+=calc(lOffset,panel,wall); cout<<lHeight<<" "<<lOffset<<" "<<cnt<<endl; } /*Square*/ cout<<wall.s()-cnt*panel.s()<<endl; return 0; }
- 1