↓ 跳过正文
  1. Posts/

uva 1587 Box(思路)

·527 字·2 分钟

给6个矩形的长和宽(或者宽和长),问这六个矩形能否组成一个长方体.

思路比较简单,不过需要注意的地方有点多.

首先由于长和宽的顺序为止,所以要处理一下(一开始只处理了后来读入的五组,没有处理单独读入的第一组,差评)

然后要判断能否分成两两相同的三组.

如果能,枚举8种可能的相等的情况.

代码实现
  1/*************************************************************************
  2	> File Name: code/uva/1587.cpp
  3	> Author: 111qqz
  4	> Email: rkz2013@126.com
  5	> Created Time: 2015年09月22日 星期二 12时20分58秒
  6 ************************************************************************/
  7#include<iostream>
  8#include<iomanip>
  9#include<cstdio>
 10#include<algorithm>
 11#include<cmath>
 12#include<cstring>
 13#include<string>
 14#include<map>
 15#include<set>
 16#include<queue>
 17#include<vector>
 18#include<stack>
 19#include<cctype>
 20#define y1 hust111qqz
 21#define yn hez111qqz
 22#define j1 cute111qqz
 23#define ms(a,x) memset(a,x,sizeof(a))
 24#define lr dying111qqz
 25using namespace std;
 26#define For(i, n) for (int i=0;i<int(n);++i)
 27typedef long long LL;
 28typedef double DB;
 29const int inf = 0x3f3f3f3f;
 30struct Q
 31{
 32    int w,h;
 33}a,b,c,q[10];
 34bool ok ( int i)
 35{
 36    if (q[i].w==q[i+1].w&&q[i].h==q[i+1].h) return true;
 37    return false;
 38}
 39bool solve ()
 40{
 41    if (a.w==b.w&&a.h==c.h&&b.h==c.w) return true;
 42    if (a.w==b.h&&a.h==c.h&&b.w==c.w) return true;
 43    if (a.w==b.w&&a.h==c.w&&b.h==c.h) return true;
 44    if (a.w==b.h&&a.h==c.w&&b.w==c.h) return true;
 45    if (a.w==c.w&&a.h==b.h&&b.w==c.h) return true;
 46    if (a.w==c.w&&a.h==b.w&&b.h==c.h) return true;
 47    if (a.w==c.h&&a.h==b.w&&b.h==c.w) return true;
 48    if (a.w==c.h&&a.h==b.h&&b.w==c.w) return true;
 49    return false;
 50}
 51bool cmp(Q a,Q b)
 52{
 53    if (a.w<b.w) return true;
 54    if (a.w==b.w&&a.h<b.h) return true;
 55    return false;
 56}
 57int main()
 58{
 59  #ifndef  ONLINE_JUDGE
 60   freopen("in.txt","r",stdin);
 61  #endif
 62   while (scanf("%d %d",&q[0].w,&q[0].h)!=EOF)
 63    {
 64	if (q[0].w>q[0].h) swap(q[0].w,q[0].h);
 65	for ( int i = 1 ; i < 6 ; i++)
 66	{
 67	   // scanf("%d %d",&w[i],&h[i]);           //蠢了..开始开了两个数组读的长和宽.排序后对应关系就打乱了233
 68	    scanf("%d %d",&q[i].w,&q[i].h);
 69	    if (q[i].w>q[i].h) swap(q[i].w,q[i].h);
 70	}
 71	bool flag = true;
 72	sort(q,q+6,cmp);
 73//	for ( int i = 0 ; i < 6 ; i++) cout<<q[i].w<<" "<<q[i].h<<endl;
 74	for ( int i = 0 ; i < 6 ; i = i + 2)
 75	{
 76	    if (!ok(i))
 77	    {
 78		flag = false;
 79		break;
 80	    }
 81	}
 82	if (!flag)
 83	{
 84	    puts("IMPOSSIBLE");
 85	    continue;
 86	}
 87	a.w = q[0].w; a.h=q[0].h;
 88	b.w = q[2].w; b.h=q[2].h;
 89	c.w = q[4].w; c.h=q[4].h;
 90//	cout<<a.w<<" "<<a.h<<endl;
 91//	cout<<b.w<<" "<<b.h<<endl;
 92//	cout<<c.w<<" "<<c.h<<endl;
 93	if (solve())
 94	{
 95	    puts("POSSIBLE");
 96	}
 97	else
 98	{
 99	    puts("IMPOSSIBLE");
100	}
101    }
102 #ifndef ONLINE_JUDGE
103  fclose(stdin);
104  #endif
105	return 0;
106}

相关文章

nim遊戲的必勝策略(博弈論)

·734 字·2 分钟
假设有n堆石子,每堆石子的个数分别如下 a1, a2, a3, … an 定义nim-sum为a1^a2^a3…an 可以证明 1. 若a1^a2^a3…an != 0 则经过一次合法的移动之后必定可变成

bestcoder #56 div 2 B Clarke and problem(dp)

·437 字·1 分钟
果然dp還是弱項啊啊啊啊.. 不過比最開始的完全無從下手強了不少應該... 至少dp狀態表示相對了....轉移方程沒想出來嗚嗚嗚 官方題解:设d(i, j)d(i,j)表示前ii个数,模pp为jj的方案数,则容易得到d(0, 0)=1, d(i, j)=d(i-1, j)+sum_{j=0}^{p-1} d(i-1, (j-a[i]) mod p)d(0,0)=1,d(i,j)=d(i−1,j)+∑j=0p−1d(i−1,(j−a[i]) mod p),很多人没1a是因为没注意|a_i| le 10^9∣ai∣≤109

best coder #56 div 2 A Clarke and minecraft(贪心)

·303 字·1 分钟
贪心..尽量把一样的材料放在一起... 然后写蠢了..妈蛋... 详情见代码 代码实现 1/************************************************************************* 2 > File Name: code/bc/#56/1001.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年09月19日 星期六 18时55分49秒 6 ************************************************************************/ 7 8#include<iostream> 9#include<iomanip> 10#include<cstdio> 11#include<algorithm> 12#include<cmath> 13#include<cstring> 14#include<string> 15#include<map> 16#include<set> 17#include<queue> 18#include<vector> 19#include<stack> 20#include<cctype> 21#define y1 hust111qqz 22#define yn hez111qqz 23#define j1 cute111qqz 24#define ms(a,x) memset(a,x,sizeof(a)) 25#define lr dying111qqz 26using namespace std; 27#define For(i, n) for (int i=0;i<int(n);++i) 28typedef long long LL; 29typedef double DB; 30const int inf = 0x3f3f3f3f; 31const int N=5E2+7; 32int a[N],b[N]; 33int ans,cnt; 34int p[N]; 35int n; 36int main() 37{ 38 #ifndef ONLINE_JUDGE 39 freopen("in.txt","r",stdin); 40 #endif 41 int T; 42 cin>>T; 43 while (T--) 44 { 45 ans = 0; 46 cnt = 0; 47 ms(p,0); 48 scanf("%d",&n); 49 for ( int i = 0 ; i < n ; i++ ) 50 { 51 scanf("%d %d",&a[i],&b[i]); 52 p[a[i]]+=b[i]; 53 } 54 int kind = 0; 55 for ( int i = 1 ;i <= 500 ; i++) 56 { 57 if (p[i]!=0) 58 { 59 // cnt = cnt + (p[i]-1)/64 + 1; 60 cnt = cnt + (p[i]+63)/64; //这样写不知高到哪里去了. 61 p[i] = 0; 62 } 63 64 } 65 //ans = ans + (cnt-1)/36+1; 66 ans = (cnt+35)/36; //不知高到哪里去了... 67 printf("%d\n",ans); 68 69 70 } 71 72 73 #ifndef ONLINE_JUDGE 74 fclose(stdin); 75 #endif 76 return 0; 77}