zoukankan      html  css  js  c++  java
  • CF-578 Div2

    A.

    题意: 模拟操作,有九间房子(0~9)L代表某人入住从左往右起第一个为空的房间,R表示从右往左起第一个空的房价。
    数字i代表第i个房间的人离开房间。最后输出房间的入住状态,有人则输出为1,没人则输出0
    思路:一开始没有读懂题意,以为是模拟双端队列那种.其实就是遍历到第一个为0的地方改为1即可

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #define IOS ios::sync_with_stdio(0); cin.tie(0);
    using namespace std;
    const int maxn = 15;
    int arr[maxn];
    int main(){
        IOS
        int n;
        while(cin>>n){
            string s;
            cin>>s;
            memset(arr,0,sizeof(arr));
            for(int i =0 ;i<s.size();i++){
                if(s[i]=='L') {
                    for(int i=0;i<10;i++){
                        if(arr[i]==0){
                            arr[i] = 1;
                            break;
                        } 
                    }
                }
                else if(s[i]=='R') {
                    for(int i = 9;i>=0 ;i--){
                        if(arr[i] == 0){
                            arr[i] = 1;
                            break;
                        }
                    }
                }
                else {
                    arr[s[i]-'0'] = 0;
                }
            }
            for(int i=0;i<10;i++){
                cout<<arr[i];
            }
            cout<<endl;
        }
    }

    B.

    题意:一行n个列,每列上有多个块,然后一开始角色站在第一个块,问能否从第一列出发到达第n列
    每次从i列到i+1列有条件:当| H(i) - H(i+1) | <= k 时才能移动,H代表第i列的块数,即相邻两列相差为K以内就能移动
    同时角色还有一个袋子可以将该列的块装入袋子中,即可以通过装入袋子来减少该列的块数即达到移动条件
    也可以将袋子中剩余的块拿出增加该列的块数以达到移动条件。
    输入:给出n(<=100),m(<=1e6),k(<=1e6) 分别代表列数,包中起始的块数,以及移动条件(相差为k)
    思路:要使每次满足移动关系我们可以尽可能使包中的块数足够多,这样之后如果需要增加高度的话就可以有足够的块拿出以达到条件
    所以我们每次要将该列拿到 H(i+1) - k 的高度,然后计算途中bag中剩余数会不会小于0.如果最后走完仍有剩余就可以,所以是一道贪心题

    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    #define IOS ios::sync_with_stdio(0); cin.tie(0);
    using namespace std;
    const int maxn = 1e5+5;
    int bag;
    int n,m,k;
    int arr[maxn];
    int flag ;
    int main(){
        IOS
        int T;
        cin>>T;
        while(T--){
            cin>>n>>m>>k;
            flag = 0;
            bag = m;
            for(int i= 0;i<n;i++){
                cin>>arr[i];
            }
            bag += arr[0];
            for(int i = 1;i<n;i++){
                if(bag - (arr[i]-k) < 0 ) {flag = 1; break;}
                else {
                    if(arr[i] < k) bag += arr[i];
                    else bag += k;
                }
            }
            if(n==1) {cout<<"YES"<<endl; continue;}
            else{
                if(flag) cout<<"NO"<<endl;
                else cout<<"YES"<<endl;
            }    
        }
    }
  • 相关阅读:
    poj 3422 Kaka's Matrix Travels
    poj 1815 Friendship
    poj 1966 Cable TV Network
    黑暗
    【bzoj2741】[FOTILE模拟赛] L
    整数拆分
    LCIS
    原题的旅行
    【codeforces gym】Increasing Costs
    【noip模拟】D(==)
  • 原文地址:https://www.cnblogs.com/Tianwell/p/11337449.html
Copyright © 2011-2022 走看看