NOIP2017Day1

T1

小学奥数。。。。。代码极短,不过要注意1e9^2超过了long long,所以要用无符号长整型

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
inline int read()
{
    char ch=getchar();
    int a=0,t=1;
    while(ch<'0'||ch>'9') {if(ch=='-') t=-1;ch=getchar();}
    while(ch<='9'&&ch>='0') {a=a*10+ch-'0';ch=getchar();}
    return a*t;
}
inline void write(int k){
    if (k<0) {
        putchar('-');
        k=-k;
    }
    if (k>9) write(k/10);
    putchar(k%10+'0');
}
int main(){
    long long a,b;
    scanf("%lld%lld",&a,&b);
    printf("%lld
",a*b-a-b);
    return 0;
}

T2

先判断ERR的情况,再开栈判断时间复杂度

#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    char ch=getchar();
    int a=0,t=1;
    while(ch<'0'||ch>'9') {if(ch=='-') t=-1;ch=getchar();}
    while(ch<='9'&&ch>='0') {a=a*10+ch-'0';ch=getchar();}
    return a*t;
}
inline void write(int k){
    if (k<0) {
        putchar('-');
        k=-k;
    }
    if (k>9) write(k/10);
    putchar(k%10+'0');
}
string s[101][4],ss;
int tot=0,op[100005],ed[100005],a[100005];
inline bool judge(string a,string b){
    if (a.size()>b.size()) return true;
    if (a.size()<b.size()) return false;
    for (int i=0;i<a.size();i++){
        if (a[i]>b[i]) return true;
        if (a[i]<b[i]) return false;
    } 
    return false;
}
int main(){
    int T=read();
    for (int i=1;i<=T;i++){
        int L=read(); cin>>ss; bool p=false,f=false;
        int tim;
        for (int j=2;j<ss.length()-1;j++){
            if (ss[j]=='n') p=true;
            if (ss[j]>='0' && ss[j]<='9') tim=ss[j]-'0';
        }//printf("%d %d
",p,tim);
        for (int j=1;j<=L;j++){
            cin>>s[j][0]; if (s[j][0]=="E") continue;
            cin>>s[j][1]; cin>>s[j][2]; cin>>s[j][3];
        }
        int numf=0,nume=0;
        for (int j=1;j<=L;j++){
            if (s[j][0]=="F") numf++;
            else nume++;
            if (nume>numf){
                f=true; printf("ERR
");
            }
        }
        if (numf>nume) printf("ERR
"),f=true;
        if (f) continue;
        int last=0;
        for (int j=1;j<=L;j++){
            if (s[j][0]=="E") last=j;
            for (int k=last+1;k<j;k++){
                if (s[j][1]==s[k][1]){
                    printf("ERR
"); f=true; break;
                }
            }
            if (f) break;
        }
        if (f) continue;
        int nums=0,numss=0,ans=0,o=0;
        for (int j=1;j<=L;j++){
            if (s[j][0]=="F") a[++tot]=j;
            else ed[a[tot]]=j,op[j]=a[tot],tot--;
        }
        int j=0;
        while (j<L){
            j++;
            if (s[j][0]=="F"){
                if (s[j][2]=="n" && s[j][3]!="n"){
                    j=ed[j]; continue;
                }
                if (s[j][2]!="n" && s[j][3]=="n") o++;
                if (s[j][2]!="n" && s[j][3]!="n"){
                    if (judge(s[j][2],s[j][3])){
                        j=ed[j]; continue;
                    }
                }
            }
            else{
                if (s[op[j]][2]!="n" && s[op[j]][3]=="n") o--;
            }
            ans=max(ans,o);
        }
        //printf("%d
",ans);
        if (ans>0){
            if (p && tim==ans) printf("Yes
");
            else printf("No
");
        } 
        else{
            if (!p && tim==1) printf("Yes
");
            else printf("No
");
        }
    } 
    return 0;
}

T3

图上最短路+图上dp

原文地址:https://www.cnblogs.com/lztlztlzt/p/7833100.html