数学规律,一元二次方程求最大值。
2015-12-05 21:55
465 查看
E - E
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status
Description
A group of N Internet Service Provider companies (ISPs) use a private communication channel that has a maximum capacity of C traffic units per second. Each company transfers T traffic units per second through
the channel and gets a profit that is directly proportional to the factor T(C - T*N). The problem is to compute the smallest value of T that maximizes the total profit the N ISPs can get from using the channel.
Notice that N, C, T, and the optimalT are integer numbers.
Input
Input starts with an integer T (≤ 20), denoting the number of test cases.
Each case starts with a line containing two integers N and C (0 ≤ N, C ≤ 109).
Output
For each case, print the case number and the minimum possible value of T that maximizes the total profit. The result should be an integer.
Sample Input
6
1 0
0 1
4 3
2 8
3 27
25 1000000000
Sample Output
Case 1: 0
Case 2: 0
Case 3: 0
Case 4: 2
Case 5: 4
Case 6: 20000000
题意:求一元二次方程T*(C-N*T)取得最大值时,T的值是多少。
ac代码:
//坑死,关键还是对题目的理解。
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
int T;
scanf("%d",&T);
for(int i=1;i<=T;i++){
long long N,C;
scanf("%lld%lld",&N,&C);
if(N==0){
printf("Case %d: %d\n",i,0);
continue ;
}
long long n,m;
float mid;
mid=(float)C/2/N;
n=floor(mid);//向下取整
m=ceil(mid);//向上取整
long long ans;
long long temp1=n*(C-N*n),temp2=m*(C-N*m);
if(temp1>=temp2){//尽量减少使用实数进行大小的判断。
ans=n;
}
else
ans=m;
printf("Case %d: %lld\n",i,ans);
}
return 0;
}
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status
Description
A group of N Internet Service Provider companies (ISPs) use a private communication channel that has a maximum capacity of C traffic units per second. Each company transfers T traffic units per second through
the channel and gets a profit that is directly proportional to the factor T(C - T*N). The problem is to compute the smallest value of T that maximizes the total profit the N ISPs can get from using the channel.
Notice that N, C, T, and the optimalT are integer numbers.
Input
Input starts with an integer T (≤ 20), denoting the number of test cases.
Each case starts with a line containing two integers N and C (0 ≤ N, C ≤ 109).
Output
For each case, print the case number and the minimum possible value of T that maximizes the total profit. The result should be an integer.
Sample Input
6
1 0
0 1
4 3
2 8
3 27
25 1000000000
Sample Output
Case 1: 0
Case 2: 0
Case 3: 0
Case 4: 2
Case 5: 4
Case 6: 20000000
题意:求一元二次方程T*(C-N*T)取得最大值时,T的值是多少。
ac代码:
//坑死,关键还是对题目的理解。
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
int T;
scanf("%d",&T);
for(int i=1;i<=T;i++){
long long N,C;
scanf("%lld%lld",&N,&C);
if(N==0){
printf("Case %d: %d\n",i,0);
continue ;
}
long long n,m;
float mid;
mid=(float)C/2/N;
n=floor(mid);//向下取整
m=ceil(mid);//向上取整
long long ans;
long long temp1=n*(C-N*n),temp2=m*(C-N*m);
if(temp1>=temp2){//尽量减少使用实数进行大小的判断。
ans=n;
}
else
ans=m;
printf("Case %d: %lld\n",i,ans);
}
return 0;
}
相关文章推荐
- 电子或通信领域当前的主流技术及其谁会需求调查报告
- 面向对象六原则
- [简单实用系列] 通用adapter
- ECMAScript 关键字与保留字
- Android Permission 机制
- Spring的MVC相比Structs2有什么优点
- day3
- day4
- ZYB's Biology
- zoj 3349 Special Subsequence 【离散化二分 + 线段树优化dp】
- POJ 2007 Scrambled Polygon (凸包输出点路径)
- 异步调用实现java
- tyvj P1039 线段树点修改和区间查询
- 浏览器处理 前台传递的+时出现问题
- 【Leetcode】Rotate Image
- Android中startActivity中的permission检测与UID机制
- MYSQL的binary解决mysql数据大小写敏感问题
- 如何在RHEL/CentOS 7.0中使用tmpfs
- 黑马程序员-Java的面向对象(抽象类、接口、内部类和继承、组合、多态)
- ospf point-to-point 网络类型