1 条题解
-
0
解题思路:
- 首先,读取并存储所有图形文件的信息,包括文件名、高度、宽度和像素数据。
- 接着,解析 CSS 样式表,提取每个图形的位置、定位方式、文件名和图层等信息。
- 对于绝对定位的图形,直接根据给定的坐标将其绘制到结果图形中。
- 对于相对定位的图形,需要根据其参照图形的位置来计算实际绘制位置,然后进行绘制。
- 按照图层从低到高、同一图层按出现顺序的规则,依次将图形绘制到结果图形上。
实现步骤:
- 读取图形文件:读取每个图形文件的信息,存储在合适的数据结构中,如结构体数组或容器。
- 解析 CSS 样式表:逐行读取 CSS 条目,提取属性值并存储在相应的数据结构中。
- 计算图形位置:对于相对定位的图形,根据参照图形的位置计算其实际绘制位置。
- 绘制图形:按照图层顺序,将每个图形绘制到结果图形中,注意处理透明像素。
- 输出结果:输出绘制好的结果图形,去除多余的空白行和列,但保留边界的透明像素。 代码:
#include<map> #include<string> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define M 1010 using namespace std; struct point{ int x,y; point(){} point(int _,int __):x(_),y(__){} point operator + (const point z) const { point re; re.x=x+z.x; re.y=y+z.y; return re; } void Read() { scanf("%d%d",&x,&y); } }; struct picture{ point size; char image[110][110]; }pictures[110]; struct entry{ point pos; int file; int layer; bool operator < (const entry &x) const { return layer < x.layer; } }entries[510]; int max_x,max_y; int n,m,cnt; char ans[M][M]; char s[M]; string st; map<string,int>picture_file,entry_file; void Initialize() { printf("Scenario #%d:\n",++cnt); max_x=max_y=0; memset(ans,' ',sizeof ans); picture_file.clear(); entry_file.clear(); } void Draw(const entry &e) { int i,j; const picture &p=pictures[e.file]; max_x=max(max_x,e.pos.x+p.size.x-1); max_y=max(max_y,e.pos.y+p.size.y-1); for(i=0;i<p.size.x;i++) for(j=0;j<p.size.y;j++) if(p.image[i][j]!='.') ans[e.pos.x+i][e.pos.y+j]=p.image[i][j]; } void Output() { int i,j; for(i=0;i<=max_x;i++) { ans[i][max_y+1]=0; puts(ans[i]); } puts(""); } inline void Kill_Char(int x) { char c; for(;x;x--) do c=getchar(); while(c==' '||c=='\t'||c=='\n'||c=='\r'); } char Get_Char() { char c; do c=getchar(); while(c==' '||c=='\t'||c=='\n'||c=='\r'); return c; } inline void Kill_Colon() { int k=strlen(s+1); if(s[k]==';') s[k]=0; else Kill_Char(1); } int main() { //freopen("1.txt","w",stdout); int T,i,j,k; point temp; char c; for(cin>>T;T;T--) { Initialize(); cin>>n; for(i=1;i<=n;i++) { cin>>st; picture_file[st]=i; pictures[i].size.Read(); getchar(); for(j=0;j<pictures[i].size.x;j++) scanf("%s",pictures[i].image[j]); } cin>>m; for(i=1;i<=m;i++) { Kill_Char(1); st.clear(); while(c=Get_Char(),c!='{') st+=c; entry_file[st]=i; Kill_Char(6); scanf("%d",&temp.y); Kill_Char(9); scanf("%d",&temp.x); Kill_Char(12); entries[i].pos=point(-1,-1); s[0]=Get_Char(); if(s[0]=='a') entries[i].pos=temp,Kill_Char(8); else { Kill_Char(8); scanf("%s",s+1); Kill_Colon(); int fa=entry_file[string(s+1)]; entries[i].pos=entries[fa].pos+temp; } Kill_Char(5); scanf("%s",s+1); Kill_Colon(); entries[i].file=picture_file[string(s+1)]; Kill_Char(6); scanf("%s",s+1); Kill_Colon(); sscanf(s+1,"%d",&entries[i].layer); Kill_Char(1); } stable_sort(entries+1,entries+m+1); for(i=1;i<=m;i++) Draw(entries[i]); Output(); } }
- 1
信息
- ID
- 1495
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 2
- 已通过
- 1
- 上传者