ZOJ 3706 Friends

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZOJ 3706 Friends相关的知识,希望对你有一定的参考价值。

Link

暴力

Code:

 1 #include<bits/stdc++.h>
 2 
 3 void solve();
 4 int __search(int a,int b,int c);
 5 
 6 int f[128][128][128];
 7 
 8 int main(){
 9     int t;
10     scanf("%d",&t);
11     while(t--)
12         solve();
13     return 0;
14 }
15 
16 void solve(){
17     int x,y,res ;
18     res = 0xffffffff;
19     scanf("%d%d",&x,&y);
20     for(int i = 1;i <= x/2;i++)
21         res =std::max(res,__search(i,x-i,y));
22     for(int i = 1;i <= y/2;i++)
23         res = std::max(res,__search(x,i,y-i));
24     printf("%d\n",res);
25 }
26 
27 int __search(int a,int b,int c){
28     int v[1024];
29     int res;
30     res = 0;
31     memset(v,0,sizeof(v));
32     if(a>b)std::swap(a,b);
33     if(a>c)std::swap(a,c);
34     if(b>c)std::swap(b,c);
35 
36     v[a]=v[b]=v[c]=1;
37     v[a+b]=v[a+c]=v[b+c]=v[b-a]=v[c-a]=v[c-b] = 1;
38     v[a+b+c] =1;
39     v[b+c-a] = v[a+c-b]= v[abs(a+b-c)] =1;
40     //printf("\n%d %d %d\n",a,b,c);
41     for(int i = 1;i < 300;i++)
42         if(v[i]){
43             res ++;
44             //printf("%d ",i);
45         }
46     return res;
47 
48 }

 

以上是关于ZOJ 3706 Friends的主要内容,如果未能解决你的问题,请参考以下文章

ZOJ What Kind of Friends Are You?

F - Friends ZOJ - 3710(暴力)

zoj 3960 What Kind of Friends Are You?(哈希)

ZOJ 3960 What Kind of Friends Are You?(读题+思维)

ZOJ 3960: What Kind of Friends Are You?

Inviting Friends(hdu3244 &amp;&amp; zoj3187)完全背包+二分