NOIP 提高组 2005

102 篇文章 1 订阅
39 篇文章 0 订阅

洛谷P1051谁拿了最多的奖学金

//就是模拟
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 105
struct Data{
    string name;
    int final_grade,calss_grade,paper,id;
    bool is_lender,is_west;
    int sum;
}s[MAXN];
long long sum;
inline bool cmp(Data a,Data b){
    if(a.sum == b.sum) return a.id < b.id; 
    return a.sum > b.sum;
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        s[i].id=i; s[i].sum=0;
        cin>>s[i].name>>s[i].final_grade>>s[i].calss_grade;
        char c,cc; cin>>c>>cc;
        s[i].is_lender=c-'N',s[i].is_west=cc-'N';
        cin>>s[i].paper;
    }
    for(int i=1;i<=n;i++){
        if(s[i].paper>=1&&s[i].final_grade>80) s[i].sum+=8000;
        if(s[i].calss_grade>80&&s[i].final_grade>85) s[i].sum+=4000;
        if(s[i].final_grade>90) s[i].sum+=2000;
        if(s[i].is_west&&s[i].final_grade>85) s[i].sum+=1000;
        if(s[i].is_lender&&s[i].calss_grade>80) s[i].sum+=850;
        sum+=s[i].sum;
    }

    sort(s+1,s+n+1,cmp);
    cout<<s[1].name<<endl<<s[1].sum<<endl<<sum;
    return 0;
}

洛谷P1052过河

//DP  看数据规模发现有很大一段是不会有石子的,压缩掉
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int pos[105],l,s,t,m,f[50000];
bool check[51000];
int main(){
    cin>>l>>s>>t>>m;
    memset(f,0x3f,sizeof f );
    for(int i=1;i<=m;++i) cin>>pos[i];
    pos[0]=0;
    sort(pos+1,pos+m+1);
    if(t==s){
        int ans=0;
        for(int i=1;i<=m;++i) if(pos[i]%s==0) ++ans;
        printf("%d\n",ans); return 0;
    }
    for(int i=1;i<=m;++i){
        int T=pos[i]-pos[i-1]-t;
        if(T>0) for(int j=i;j<=m;++j) pos[j]-=T;
    }
    for(int i=1;i<=m;++i) check[pos[i]]=true;
    l=pos[m]+t;
    f[s]=check[s];
    for(int i=s;i<=l;++i){
        for(int j=s;j<=t;++j)
            if(i>=j) f[i]=min(f[i],f[i-j]);
        f[i]+=check[i];
    }
    printf("%d\n",f[l]);
    return 0;
}

洛谷P1053篝火晚会

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define INF 1000000000
#define MAXN 50005
#define Mod 1000000007
inline void read(int &x){
    x=0; int f=1; char c=getchar();
    while(c>'9'||c<'0'){ if(c=='-') f=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ x=x*10+c-'0'; c=getchar(); } x*=f;
}
int n,ans,c[MAXN],laft[MAXN],reght[MAXN],t1[MAXN],t2[MAXN];
bool vis[MAXN];
int main(){
    read(n);
    for(int i=1;i<=n;++i) read(laft[i]),read(reght[i]);
    c[1]=1,c[2]=laft[1];
    vis[c[1]] = vis[c[2]] = 1;
    for(int i=2;i<n;++i){
        if(c[i-1] == laft[c[i]]) c[i+1] = reght[c[i]];
        else if(c[i-1] == reght[c[i]]) c[i+1] = laft[c[i]];
        else { puts("-1"); return 0; }
        vis[c[i+1]] = 1;
    }
    for(int i=1;i<=n;++i)
        if(!vis[i]) { puts("-1"); return 0; }
    for(int i=1;i<=n;++i){
        int t=(c[i]-i+n)%n;
        t1[t]++;
        ans=max(ans,t1[t]);
        t=(c[n-i+1]-i+n)%n;
        t2[t]++;
        ans=max(ans,t2[t]);
    }
    printf("%d\n",n-ans);
    return 0;
}

洛谷P1054等价表达式

//带入数字检验 最好带质数  模拟求中缀表达式的过程
#include<iostream>
#include<cstring>
#include<cstdio>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
#define LL long long 
#define Mod 200600801
char ch[60][500];
int map[500];
struct stack{
    LL num[150101];
    int topp;
    inline bool empty(){ return topp==0 ? 1 : 0; }
    inline void push(LL x){ num[++topp]=x; }
    inline void pop(){ topp--; }
    inline LL top(){ if(topp>=1) return num[topp]; }
}st1,st2;

LL pow(LL a,LL b){
    LL ans=1,p=a;
    for(;b;b>>=1,p*=p,p%=Mod)
        if(b&1) ans*=p,ans%=Mod;
    return ans;
}

inline void solve(){
    int q=st2.top(); st2.pop();
    if(q==1||q==2) return ;
    LL num1=st1.top(); st1.pop();
    LL num2=st1.top(); st1.pop();
    if(q == 4) st1.push((((num2-num1)%Mod)+Mod)%Mod);
    else if(q == 3) st1.push((num2+num1)%Mod);
    else if(q == 5) st1.push((num2*num1)%Mod);
    else if(q == 6) st1.push((pow(num2,num1))%Mod);
    return;  
}

LL calc(char *ch1,int value){//计算某个表达式的值 
    while(!st1.empty()) st1.pop();
    while(!st2.empty()) st2.pop();
    LL num=0; bool ok=0;
    for(int i=0;1;++i){
        const char c=ch1[i];
        if(c==' ') continue;
        if(c=='a'){
            st1.push(value);continue;
        }

        if(c>='0'&&c<='9') num=num*10+c-'0',ok=1;
        else if(ok) num%=Mod,st1.push(num),num=0,ok=0;
        if(c=='\0') break;

        if(map[c]!=0){
            int p=map[c];
            if(p==1) st2.push(p);
            else if(p==2){
                while(st2.top()!=1){
                    if(st2.top()==2) st2.pop();
                    solve();
                }
                st2.pop();
            } else {
                while(!st2.empty()&&p<=st2.top()) solve();
                st2.push(p);
            }
        }
    }
    while(!st2.empty()) solve();
    return st1.top();
}

int main(){
    map['(']=1;map[')']=2;map['+']=3;
    map['-']=4;map['*']=5;map['^']=6;
    gets(ch[0]);
    int n;
    scanf("%d",&n);
    getchar(); getchar();
    for(int i=1;i<=n;++i) gets(ch[i]);

    for(int i=0;i<=n;++i){
        int a1=0;
        for(int j=0;ch[i][j]!='\0';++j){
            if(ch[i][j]=='(') a1++;
            if(ch[i][j]==')') {
                if(a1>=1) a1--;
                else ch[i][j]=' ';
            }
        }
    }
    LL num1=calc(ch[0],3);
    LL num2=calc(ch[0],7);
    for(int i=1;i<=n;++i){
        LL num3=calc(ch[i],3),num4=calc(ch[i],7);
        if(num1==num3&&num2==num4)
            printf("%c",'A'+i-1);
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七情六欲·

学生党不容易~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值