比赛 20111012 评测结果 AWAAAWWAWW
题目名称 抗击SARS 最终得分 50
用户昵称 fanzeyi 运行时间 0.000 s
代码语言 C 内存使用 0.00 MiB
提交时间 2011-10-12 20:17:55
显示代码纯文本
/*
ID: fanzeyi1
LANG: C
TASK: sars 
*/
/*
 * =====================================================================================
 *
 *       Filename:  sars.c
 *        Version:  1.0
 *        Created:  10/12/2011 07:25:41 PM
 *       Revision:  none
 *       Compiler:  gcc
 *         Author:  Zeray Fan, fanzeyi1994[at]gmail.com
 *        Company:  http://www.fanhe.org/
 *
 * =====================================================================================
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int count = 0; 
int snum = 1; 
double r; 
double v; 
double house; 
double sars[10000]; // 坐标轴 
double speed; 

int main(void) {
    FILE *fin = fopen("sars.in","r");
    FILE *fout = fopen("sars.out", "w");
    int a; 
    int i; 
    fscanf(fin, "%lf %lf %lf %lf", &sars[0], &r, &speed, &v);
    house = 0; 
    while(1) {
        // 移动房子
        house = house + v; 
        // 检查 半径内有无房子
        for( i = 0 ; i < snum ; i++ ) {
            if((sars[i] <= house && sars[i] >= house - v) || // 病毒在房子移动区域内
                (sars[i] + r >= house && sars[i] - r <= house) || // 房子移动后进入病毒区域
                (sars[i] + r >= house - v && sars[i] - r <= house) // 房子移动前在病毒区域
                ) {
                count = count + 1; 
            }
        }
        a = snum; 
        // 分裂病毒 
        for( i = 0 ; i < a ; i++ ) {
            sars[snum] = sars[i] + speed; 
            sars[i] = sars[i] - speed; 
            snum = snum + 1; 
        }
        if(speed < 1) {
            break; 
        }
        // 减慢速度
        speed = speed / 2; 
    }
    fprintf(fout, "%d\n", count); 
    return 0;
}