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 }
时间: 2024-12-04 16:56:32

ZOJ 3706 Friends的相关文章

ZOJ 3706 Break Standard Weight 解题报告

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5009 题目意思:给出两个mass:x 和 y,问如何将其中一个 mass 一分为二(当然分完之后它们的和要等于原来的mass,或x 或 y),使得利用这三个mass 可称的数量最大.输出这个最大数量. 网上参考别人用STL中的set来写,太厉害了!!!考虑到set对于重复的元素只存储一个,那么当三个mass组合的过程中有重复的,它都会自动舍弃有重复的,不需要用if来

ZOJ 3706 Break Standard Weight (模拟题)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3706 题意: 给你两个标准重量的物体(质量为整数),你可以选择将其中一个分成两块(整数),求用这三个物体最多可以称出多少种重量. 其实一共就13种情况,数据量又比较小,用set排除一下重复的,注意下0就好. 代码: #include <iostream> #include <cstdio> #include <set> #include

zoj 3706 Break Standard Weight

分治的思想,比较水,但题很好 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int t,n,m; int vis[50010]; void v(int a,int b) { vis[a]=1;vis[b]=1; vis[a+b]=1;vis[abs(a-b)]=1; } int rmax(int a,int b,int c) { int rcount=0; mems

zoj 3706 Break Standard Weight(dp)

Break Standard Weight Time Limit: 2 Seconds                                     Memory Limit: 65536 KB The balance was the first mass measuring instrument invented. In its traditional form, it consists of a pivoted horizontal lever of equal length ar

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 最小生成树 Kruskal算法

题目链接:ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 Building a Space Station Time Limit: 2 Seconds      Memory Limit: 65536 KB You are a member of the space station engineering team, and are assigned a task in the construction process of the statio

ZOJ 3607 Lazier Salesgirl (贪心)

Lazier Salesgirl Time Limit: 2 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy

ZOJ - 2243 - Binary Search Heap Construction

先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal n