syhd142  
日历
<2024年9月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345
统计
  • 随笔 - 23
  • 文章 - 122
  • 评论 - 31
  • 引用 - 0

导航

常用链接

留言簿(2)

随笔档案(23)

文章分类(270)

文章档案(122)

我的豆瓣

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 
题意:给你两个函数水平范围是[0,10],定义第三个函数是该区间上两个函数的最大值。水平线就是第三个函数的最小值。
解法:排序模拟就好。
#include <stdio.h>
#include 
<stdlib.h>
#include 
<algorithm>

#define N 1005

inline 
double max(double a, double b)
{
    
return a > b ? a : b;
}

struct segement
{
    
double height;
    
double start, end;
}a[N], b[N];

double step[N];

int main()
{
    
int n1, n2, n;
    
double sum;
    
while(~scanf("%d"&n1))
    {
        n 
= 1;
        sum 
= 0;
        
for(int i = 0; i < n1; i++)
        {
            scanf(
"%lf %lf"&a[i].height, &a[i].end);
            a[i].start 
= sum;
            sum 
+= a[i].end;
            a[i].end 
= sum;
            step[n
++= sum;
        }
        scanf(
"%d"&n2);
        sum 
= 0;
        
for(int i = 0; i < n2; i++)
        {
            scanf(
"%lf %lf"&b[i].height, &b[i].end);
            b[i].start 
= sum;
            sum 
+= b[i].end;
            b[i].end 
= sum;
            step[n
++= sum;
        }
        std::sort(step, step 
+ n);
        
double ans = 1e9, height1, height2;
        
for(int i = 1; i < n; i++)
        {
            
for(int j = 0; j < n1; j++)
            
if(a[j].start <= step[i - 1&& a[j].end >= step[i])
            {
                height1 
= a[j].height;
                
break;
            }
            
for(int j = 0; j < n2; j++)
            
if(b[j].start <= step[i - 1&& b[j].end >= step[i])
            {
                height2 
= b[j].height;
                
break;
            }
            
if(max(height1, height2) < ans) ans = max(height1, height2);
        }
        printf(
"%.3lf\n", ans);
    }
    
return 0;
}
posted on 2010-09-29 16:52 Fucker 阅读(323) 评论(0)  编辑 收藏 引用 所属分类: ACM/ICPC简单排序

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


 
Copyright © Fucker Powered by: 博客园 模板提供:沪江博客