codeforces 581d
来源:互联网 发布:windows正版镜像 编辑:程序博客网 时间:2024/06/04 23:33
题意:问三个矩形能不能组成一个正方形
思路:其实就只有题目给的那2种情况,枚举每个放的情况和顺序就好了
#include<cstring>#include<cstdlib>#include<iostream>#include<stdio.h>#include<cmath>#include<algorithm>#include<vector>using namespace std;#define N 2000010#define lim 200000#define MOD 1000000007#define M 1000000006#define LL long longstruct Logos{ int w; int h; int id;};Logos l[3];Logos h[3];int v[3];bool judge(){ if(l[0].w==l[1].w) { if(l[1].w==l[2].w&&l[0].h+l[1].h+l[2].h==l[0].w) { printf("%d\n",l[0].w); for(int k=0;k<3;k++) { for(int i=0;i<l[k].h;i++) { for(int j=0;j<l[k].w;j++) { printf("%c",'A'+l[k].id); } printf("\n"); } } return true; } else if(l[0].h+l[1].h==l[2].h&&l[0].w+l[2].w==l[2].h) { printf("%d\n",l[2].h); for(int j=0;j<l[2].h;j++) { for(int i=0;i<l[0].w+l[2].w;i++) { if(i>=l[0].w) printf("%c",'A'+l[2].id); else if(j<l[0].h) printf("%c",'A'+l[0].id); else printf("%c",'A'+l[1].id); } printf("\n"); } return true; } } return false;}bool dfs(int x){ if(x==3) { return judge(); } for(int i=0;i<3;i++) { if(v[i])continue; v[i]=1; l[x]=h[i]; if(dfs(x+1))return true; swap(l[x].h,l[x].w); if(dfs(x+1))return true; swap(l[x].h,l[x].w); v[i]=0; } return false;}int main(){ for(int i=0;i<3;i++){ scanf("%d%d",&h[i].w,&h[i].h); h[i].id=i; } if(!dfs(0)) printf("-1"); return 0;}
0 0
- codeforces 581d
- Codeforces 581D Three Logos
- codeforces 581D Three Logos
- Codeforces 581D - Three Logos (枚举)
- Codeforces 581D Three Logos 模拟 枚举
- CodeForces 617D CodeForces 617D
- CodeForces 101D
- CodeForces 103D
- CodeForces 222D Olympiad
- codeforces 242d
- CodeForces 111D
- 【codeforces】3D
- CodeForces 127D Password
- codeforces 257D. Sum
- Codeforces 292D
- Codeforces 275D
- Codeforces 126D
- Codeforces 337d
- Jetty使用固定长度队列,导致无法服务
- 逻辑——真与假的世界
- Android 将类中的文字提取到String.xml中
- springmvc配置
- 实际上Java访问数据库的方式主要有四种
- codeforces 581d
- android学习之选择媒体库中的图片
- jfinal 学习笔记
- Android学习之Animation(三)
- 执行django-admin.py时,打开编辑器的解决办法
- 【ASP】利用数据库操作类优化数据库表的增删改查
- java入门学习(11)—接口定义(interface)及使用(implements)
- ORA-02080:database link is in use
- System.arraycopy