zoukankan      html  css  js  c++  java
  • UVALive

    /*
      这题如果想明白以后,其实并没有那么难
      两个长方形A, B若要合并,(a1 == b1 || a1 == b2 || a2 == b1 || a2 == b2)四种条件中,必定要满足至少一个,也就是说,两个长方形必有相等的边,假设这两个长方形已经合成了一个大长方形
      
      第三个长方形,如果要和大三角形合并,除非有边和它们相等的那条边相等,或者有边和它们合并后得到的边相等
      
      因为就4种情况,循环反而并不太好,因为循环一般是4个三角形组成的排列,而非组合,可能会枚举重复的情况,虽然不会造成答案错误,但毕竟不太完美...对这题而言,枚举反而更好
      
      参考了此博客的思路:
      http://www.cnblogs.com/Ritchie/p/5741823.html
    */
    #include <iostream>
    //#define debug
    using namespace std;
    
    struct triangle
    {
    	int w, h;
    	triangle(int _w = 0, int _h = 0):w(_w), h(_h)
    	{
    	}
    	bool isvalid()
    	{
    		return (w > 0 && h > 0);
    	}
    }a[4];
    
    typedef triangle tri;
    
    tri unite(tri i, tri j)
    {
    	if (i.h == j.h) return tri(i.h, i.w + j.w);
    	if (i.h == j.w) return tri(i.h, i.w + j.h);
    	if (i.w == j.w) return tri(i.w, i.h + j.h);
    	if (i.w == j.h) return tri(i.w, i.h + j.w);
    	return tri(-1, -1);
    }
    
    bool judge(tri a, tri b, tri c)
    {
    	if (( unite( unite(a, b), c ) ).isvalid() ||  ( unite( unite(a, c), b ) ).isvalid() || ( unite( unite(b, c), a ) ).isvalid()) return true;
    	return false;
    }
    
    void solve()
    {
    	if (judge(a[0], a[1], a[2]) || judge(a[0], a[1], a[3]) || judge(a[0], a[2], a[3]) || judge(a[1], a[2], a[3])) cout << "Yes" << endl;
    	else cout << "No" << endl;
    }
    
    int main()
    {
    	#ifdef debug
    	freopen("E:\in.txt", "r", stdin);
    	freopen("E:\out.txt", "w", stdout);
    	#endif
    	int t;
    	cin >> t;
    	while (t--)
    	{
    		for (int i = 0; i < 4; i++) cin >> a[i].w >> a[i].h;
    		solve();
    	}
    	
    	#ifdef debug
    	fclose(stdin);
    	fclose(stdout);
    	#endif
    	return 0;
    } 

  • 相关阅读:
    [Python]爬虫v0.1
    [Python]同是新手的我,分享一些经验
    [python]闭包到底是什么鬼?
    测试Flask应用_学习笔记
    Flask模板_学习笔记
    SQL Server Alwayson概念总结
    JDBC数据库编程:ResultSet接口
    JDBC操作,执行数据库更新操作
    接口怎么实例化?
    java数据库编程:JDBC操作及数据库
  • 原文地址:https://www.cnblogs.com/mofushaohua/p/7789548.html
Copyright © 2011-2022 走看看