若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1114: Problem E: Hotter Colder

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,176

题目描述

Problem E: Hotter Colder
The children's game Hotter Colder is played as follows. Player A leaves the room while player B hides an object somewhere in the room. Player A re-enters at position (0,0) and then visits various other positions about the room. When player A visits a new position, player B announces "Hotter" if this position is closer to the object than the previous position; player B announces "Colder" if it is farther and "Same" if it is the same distance.
Input consists of up to 50 lines, each containing an x,y coordinate pair followed by "Hotter", "Colder", or "Same". Each pair represents a position within the room, which may be assumed to be a square with opposite corners at (0,0) and (10,10). For each line of input print a line giving the total area of the region in which the object may have been placed, to 2 decimal places. If there is no such region, output 0.00.

输入

暂无

输出

暂无

样例输入

10.0 10.0 Colder
10.0 0.0 Hotter
0.0 0.0 Colder
10.0 10.0 Hotter

样例输出

50.00
37.50
12.50
0.00

参考代码

#include <stdio.h>
#include <math.h>
char reach[1<<24];
double w[24], x[24], len, wt, sumw, sumx, cg;
int n;
int solve(int m, double sx, double sw) 
{
    int i;
    double sumt1, sumt2;
    if (reach[m]) return 0;
    reach[m] = 1;
    cg = sx / sw;
    if (cg < -1.5 || cg > 1.5) return 0;
    if (m == (1<<n)-1) return 1;
    for (i=0;i<n;i++) 
    {
        if (!(m & (1<<i)) && solve(m|(1<<i),sx+x[i]*w[i],sw+w[i])) 
        {
            printf("%lg %lgn",x[i],w[i]);
         return 1;
      }
   }
   return 0;
}
main(){
   int cc,i;
   for (cc=1; 3 == scanf("%lf%lf%d",&len,&wt,&n) && n; cc++) {
      memset(reach,0,1<<n);
      for (i=0;i<n;i++) scanf("%lf%lf",&x[i],&w[i]);
      printf("Case %d:n",cc);
      if (!solve(0,0,wt)) printf("Impossiblen");
   }
}

解析

暂无

hustoj

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

Dreams孤独患者 Skip 原站点
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist