csuoj 1391: Boiling Vegetables

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1391

1391: Boiling Vegetables

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 27  Solved: 14
[Submit][Status][Web Board]

Description

Input

Output

Sample Input

0.99 3
2000 3000 4000

Sample Output

6

HINT

Source

分析:

暴力枚举。

AC代码;

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <cmath>
 6
 7 using namespace std;
 8
 9 double vagetable[1100],limit;
10 int n;
11
12 int main()
13 {
14     cin>>limit>>n;
15     for(int i=0;i<n;i++) cin>>vagetable[i];
16
17     if(n==1)
18     {
19         cout<<0<<endl;
20         return 0;
21     }
22
23     sort(vagetable,vagetable+n,less<double>());
24
25     int ans=501;
26
27     for(int i=0;i<n;i++)
28     {
29         for(int c=0;c<ans;c++)
30         {
31             double maxsize=vagetable[i]/(c+1);
32             double minsize=maxsize*limit;
33
34             int temp=c;
35             bool flag=true;
36
37             for(int j=0;j<n;j++)
38             {
39                 if(i==j) continue;
40
41                 int c1=(int)ceil(vagetable[j]/maxsize)-1;
42
43                 if(vagetable[j]/(c1+1) < minsize)
44                 {
45                     flag=false; break;
46                 }
47                 temp+=c1;
48                 if(temp>=ans)
49                 {
50                     flag=false; break;
51                 }
52             }
53             if(flag)
54             {
55                 ans=min(ans,temp);
56             }
57         }
58     }
59     cout<<ans<<endl;
60     return 0;
61 }

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 #include<iostream>
 5 using namespace std;
 6 double a[1009];
 7 int main()
 8 {
 9     double T,maxx,minn;
10     int n,i,j,k,PP,sum,flag;
11     while(~scanf("%lf%d",&T,&n))
12     {
13         PP=600;
14         for(i=0;i<n;i++)
15             scanf("%lf",&a[i]);
16         for(i=0;i<n;i++)
17             for(j=0;j<=500;j++)
18             {
19                 sum=j;flag=0;
20                 maxx=a[i]*1.0/(j+1);
21                 minn=maxx*T;
22                 for(k=0;k<n && flag==0;k++)
23                 {
24                     if(k==i)
25                         continue;
26                     int t1=(int)((a[k]-1)/maxx);
27                     double t2=a[k]*1.0/(t1+1);
28                     if(t2<minn)
29                         {flag=1;break;}
30                     sum+=t1;
31                     if(sum>PP)
32                         {flag=1;break;}
33
34                 }
35                 if(flag==0)
36                     PP=min(PP,sum);
37             }
38         printf("%d\n",PP);
39     }
40     return 0;
41 }

时间: 2024-12-17 20:17:14

csuoj 1391: Boiling Vegetables的相关文章

2014 UESTC 暑前集训队内赛(1) 解题报告

A.Planting Trees 排序+模拟 常识问题,将耗时排一个序,时间长的先种,每次判断更新最后一天的时间. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #define Mod 1000000007 #define INT 2147483647 #define pi acos(-1.0)

BZOJ 1391: [Ceoi2008]order

Description 有一些任务,需要用到一些机器,可以买可以租,问最大获利. Solution 网络流. 最大权闭合子图模型. 建图很简单就是S->机器,机器->任务,任务->T. 如果没有租用的话,中间的是INF,不会割掉,加上租用就把容量变成租用的价格即可. 这样求出来的割就是最小损失了,用总数减去即可. Code /************************************************************** Problem: 1391 User:

CSUOJ 1010 Water Drinking

Description The Happy Desert is full of sands. There is only a kind of animal called camel living on the Happy Desert. ‘Cause they live here, they need water here. Fortunately, they find a pond which is full of water in the east corner of the desert.

CSUOJ 1217 奇数个的那个数

Description 给定些数字,这些数中只有一个数出现了奇数次,找出这个数. Input 每组数据第一行n表示数字个数,1 <= n <= 2 ^ 18 且 n % 2 == 1. 接下来n行每行一个32位有符号整数. Output 出现奇数次那个数,每组数据对应一行. Sample Input 5 1 1 2 2 3 7 1 2 1 2 2 3 3 Sample Output 3 2 看了大神的代码 使用位运算o(╯□╰)o 1 # include <stdio.h> 2 i

Aizu 2164 CSUOJ 1436 Revenge of the Round Table

dp套一个burnside的壳子核心还是dpdp[i]表示有i个循环节时的染色方案数注意在dp的时候,不需要考虑重构的问题因为burnside会解决重构的问题dpA[i][j]表示以A开头,长度为i,结尾为j个A的合法方案数dpB[i][j]表示以B开头,长度为i,结尾为j个A的合法方案数接下来我们用dpA,dpB来计算dp[i]显然对于所有的dpB[i][1~k]都是满足dp[i]的因为它表示以B开头,以A结尾的染色方案,且结尾没有超过k个另外还有一部分就是以A开头的了假设我们在整个串的最前面

BZOJ 1391: [Ceoi2008]order [最小割]

1391: [Ceoi2008]order Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1509  Solved: 460[Submit][Status][Discuss] Description 有N个工作,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序需要某种机器来完成,你可以通过购买或租用机器来完成. 现在给出这些参数,求最大利润 Input 第一行给出 N,M(1<=N<=1200,1<=M<=12

csuoj 1511: 残缺的棋盘

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 1511: 残缺的棋盘 时间限制: 1 Sec  内存限制: 128 MB 题目描述 输入 输入包含不超过10000 组数据.每组数据包含6个整数r1, c1, r2, c2, r3, c3 (1<=r1, c1, r2, c2, r3, c3<=8). 三个格子A, B, C保证各不相同. 输出 对于每组数据,输出测试点编号和最少步数. 样例输入 1 1 8 7 5 6 1 1 3 3

UVA 1391 - Astronauts(2-SET)

UVA 1391 - Astronauts 题目链接 题意:给定一些宇航员,年龄小于平均数能做A和C,大于等于能做B和C,现在知道一些宇航员互相憎恨,不能让他们做同一个任务,问一直种安排方法满足条件 思路:2set问题,如果两种宇航员类型相同,就两个宇航员做不一样,加一条真或真,和假或假的边,如果类型不同,就加一条真或真的边 代码: #include <cstdio> #include <cstring> #include <cstdlib> #include <

hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

#1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, country A and country B. They are in a war, and keep launching missiles towards each other. It is known that country A will launch N missiles. The i-th miss