zoukankan      html  css  js  c++  java
  • 2016 CCPC 东北地区重现赛

    1、 2016 CCPC 东北地区重现赛   

    2、总结:弱渣,只做出01、03、05水题

    08   HDU5929 Basic Data Structure    模拟,双端队列

    1、题意:模拟一个栈的操作,并在每次询问时,计算栈项到栈底元素nand位运算的值。

    2、总结:思路就是看距离栈底最近的0的后面1的个数的奇偶。试了好多种办法,最后还是双端队列简便。总之,贼恶心的题。。

    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<queue>
    #include<algorithm>
    #include<cstdio>
    #include<stack>
    #include<vector>
    #define F(i,a,b) for (int i=a;i<b;i++)
    #define FF(i,a,b) for (int i=a;i<=b;i++)
    #define mes(a,b) memset(a,b,sizeof(a))
    #define INF 0x3f3f3f3f
    #define LL long long
    #define pb push_back
    using namespace std;
    const int N=500500,MAX=1000100;
    
    int main()
    {
        int t,n,x,flag,tot1,tot2,a[N];
        char str[15];
        deque<int >DQ;
        scanf("%d",&t);
        FF(cas,1,t){
            DQ.clear();
            flag=0;
            tot1=((N>>1)-1),tot2=(N>>1);
            scanf("%d",&n);
            printf("Case #%d:
    ",cas);
            while(n--){
                scanf("%s",str);
                if(str[2]=='S'){
                    scanf("%d",&x);
                    if(!flag){
                        if(!x)DQ.push_back(tot1);
                        a[tot1--]=x;
                    }else {
                        if(!x)DQ.push_front(tot2);
                        a[tot2++]=x;
                    }
                }
    
                else if(str[1]=='O'){
                    if(!flag){
                        tot1++;
                        if(!a[tot1])DQ.pop_back();
                    }else {
                        tot2--;
                        if(!a[tot2])DQ.pop_front();
                    }
                }
    
                else if(str[0]=='R'){
                    flag^=1;
                }
    
                else {
                    if(tot2-tot1-1==0)puts("Invalid.");
                    else if(DQ.empty()) cout<<((tot2-tot1-1)%2)<<endl;
                    else {
                        if(!flag){
                            cout<<((tot2-DQ.front()-1+(tot1+1!=DQ.front()))%2)<<endl;
                        }else {
                            cout<<((DQ.back()-tot1-1+(DQ.back()!=tot2-1))%2)<<endl;
                        }
                    }
                }
            }
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    File
    多态
    方法重载
    Math
    instanceof
    强制类型转换
    泛型
    springboot热部署
    iOS bug处理
    iOS8-xcode6中添加pch全局引用文件
  • 原文地址:https://www.cnblogs.com/sbfhy/p/5950593.html
Copyright © 2011-2022 走看看