noip2015 普及组

T1 金币 题目传送门

就是道模拟题咯

#include<cstdio>
#include<cstring> 
#include<algorithm>
using namespace std;
int read(){
    int ans=0,f=1,c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
    return ans*f;
}
int n,sum=1,ans; 
int main()
{
    n=read();
    while(n){
        if((n-sum)<0) break;
        ans=ans+sum*sum;
        n=n-sum;
        sum++;
    }
    if(n) ans=ans+n*sum;
    printf("%d\n",ans);
    return 0;
}
View Code

T2.扫雷游戏 题目传送门

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int M=205;
int read(){
    int ans=0,f=1,c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
    return ans*f;
}
int n,m;
int xi[9]={0,0,1,0,-1,-1,1,1,-1},yi[9]={0,1,0,-1,0,1,1,-1,-1};
char s[M][M];
int w[M][M];
int check(int x,int y){return (x>=1&&x<=n&&y>=1&&y<=m);}
int get_ans(int x,int y){
    int sum=0;
    for(int i=1;i<=8;i++){
        int nx=x+xi[i],ny=y+yi[i];
        if(check(nx,ny)&&s[nx][ny]=='*') sum++;
    }
    return sum;
}
int main()
{
    n=read(); m=read();
    for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++)
     for(int j=1;j<=m;j++)
         if(s[i][j]=='?') w[i][j]=get_ans(i,j);
    for(int i=1;i<=n;i++,printf("\n"))
     for(int j=1;j<=m;j++)
      if(s[i][j]=='?') printf("%d",w[i][j]);
      else printf("*");
    return 0;
}
View Code

T3 求和  题目传送门

比较暴力的做法吧 把颜色相同的拉出来一一比较的好了

#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int M=150007,mod=10007;
LL read(){
    LL ans=0,f=1,c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
    return ans*f;
}
int last[M],old[M];
LL sum[M],n,m,ans;
int main()
{
    int k;
    n=read(); m=read();
    for(int i=1;i<=n;i++) sum[i]=read();
    for(int i=1;i<=n;i++){
        k=read();
        int now=old[k];
        while(now){
            if((i+now)%2==0) ans=(ans+(i+now)*(sum[i]+sum[now]))%mod;
            now=last[now];
        }
        last[i]=old[k]; old[k]=i;
    }
    printf("%lld\n",ans);
    return 0;
}
View Code

T4.推销员

 我们用两个堆q1 q2 一个是d*2+v一个只有v 每次拉出来比较一波就好了 不过注意如果q1用过的q2必然不能再用 所以打一波标记的好了 两个对相照应还是经常用到的

还要注意比较时q1还得减去2*mx 然后就可以写啦

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define LL long long 
using namespace std;
const int M=1e5+7;
int read(){
    int ans=0,f=1,c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
    return ans*f;
}
int v[M],d[M];
int n,mx,f[M];
struct node{
    int w,pos;
    bool operator <(const node& x)const{return x.w>w;}
};
priority_queue<node>q1,q2;
LL ans;
int main()
{
    n=read();
    for(int i=1;i<=n;i++) d[i]=read();
    for(int i=1;i<=n;i++) v[i]=read();
    for(int i=1;i<=n;i++){
        q1.push((node){2*d[i]+v[i],i});
        q2.push((node){v[i],i});
    }
    for(int i=1;i<=n;i++){
        node x,y;
        if(!q1.empty()) x=q1.top(); 
        while(!q1.empty()&&d[x.pos]<=mx){
            q1.pop();
            if(q1.empty()) break;
            x=q1.top();
        }
        y=q2.top(); 
        while(f[y.pos]){
            q2.pop(); 
            if(q2.empty()) break; 
            y=q2.top();
        }
        if(!q1.empty()&&x.w-2*mx>y.w){
            ans+=x.w-2*mx; 
            q1.pop(); f[x.pos]=1;
            mx=max(mx,d[x.pos]);
        }
        else{
            ans+=y.w;
            q2.pop();
        }
        printf("%lld\n",ans);
    }
    return 0;
}
View Code

 

posted @ 2017-07-13 22:38  友人Aqwq  阅读(112)  评论(0编辑  收藏  举报