zoukankan      html  css  js  c++  java
  • CodeForces 342B Xenia and Spies (水题模拟,贪心)

    题意:给定 n 个间谍,m个区间,一个 s,一个f,然后从 s开始传纸条,然后传到 f,然后在每个 t 时间在区间内的不能传,问你最少的时间传过去。

    析:这个题,就模拟一下就好,贪心策略,能传就传,找好方向,一直传就行,传到 f 就结束。

    代码如下:

    #include <bits/stdc++.h>
    
    using namespace std;
    struct node{
        int l, r, t;
        bool operator < (const node &p) const{
            return t < p.t;
        }
    };
    node a[100005];
    
    int main(){
        int s, t, m, n, f, l, r;
        while(cin >> n >> m >> s >> f){
            bool ok = false;
            int x = f > s ? 1 : -1;
            int pos = s;
            for(int i = 0; i < m; ++i){
                scanf("%d %d %d", &a[i].t, &a[i].l, &a[i].r);
            }
    //        sort(a, a+m);
            int cnt = 0;
            for(int i = 1; ; ++i){
                if(a[cnt].t == i){
                    if((pos + x < a[cnt].l && pos < a[cnt].l) || (pos + x > a[cnt].r && pos > a[cnt].r)){  printf("%c", x < 0 ? 'L' : 'R'); pos += x; }
                    else  printf("X");
                    if(pos == f)  break;
                    ++cnt;
                }else{
                    pos += x;
                    printf("%c", x < 0 ? 'L' : 'R');
                    if(pos == f)  break;
                }
            }
            printf("
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    233
    膝为筋之府
    AES 可逆性加密算法
    DES 可逆性加密算法
    Java Swing如何让窗体居中显示
    eclipse 安装插件
    eclipse 搭建Swt 环境
    Java Set元素比较
    Greenplum数据库中系统表gp_ distribution_ policy详解
    Greenplum数据库中系统表pg_class详解
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5652004.html
Copyright © 2011-2022 走看看