bestcoder #66

1002:

这题拿两个优先队列维护一下就可以了,近期都在做这种题,然而这题居然还是不会,why am i so stupid...

#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define MS0(a) memset(a,0,sizeof(a))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

typedef long long ll;
const int maxn=1000100;
const int INF=1<<29;

int n,m;
ll a[maxn],b[maxn],c[maxn];
ll t[maxn];

int main()
{
    freopen("in.txt","r",stdin);
    int T;cin>>T;
    while(T--){
        scanf("%d%d",&n,&m);
        REP(i,1,n) scanf("%I64d%I64d",&a[i],&b[i]);
        REP(i,1,m) scanf("%I64d",&c[i]);sort(c+1,c+m+1);
        MS0(t);
        REP(i,1,m) t[c[i]]++;
        priority_queue<ll,vector<ll>,greater<ll> > q[2];
        ll add=0;
        REP(i,1,n){
            b[i]-=add;
            while(!q[!a[i]].empty()&&q[!a[i]].top()<b[i]) q[!a[i]].pop();
            q[a[i]].push(b[i]);
            add+=t[i];
        }
        cout<<q[0].size()+q[1].size()<<endl;
    }
    return 0;
}
View Code

1003:

这题和上学期校赛的第五题如出一辙,就是打表找规律,上学期我也是靠着第五题混了个校赛第七,然而这次居然没出。。why am i so stupid...

注意打表不是手动计算!!!直接用代码循环打表!

#include<bits/stdc++.h>
#define MS0(a) memset(a,0,sizeof(a))
#define REP(i,a,b) for(int i=a;i<=b;i++)

using namespace std;

typedef long long ll;
const int maxn=1000100;
const int INF=1<<29;

ll n,x;

ll phi(ll n)
{
    ll m=(ll)sqrt(n+0.5);
    ll res=n;
    REP(i,2,m){
        if(n%i==0){
            res=res/i*(i-1);
            while(n%i==0) n/=i;
        }
    }
    if(n>1) res=res/n*(n-1);
    return res;
}

int main()
{
    freopen("in.txt","r",stdin);
    while(~scanf("%I64d%I64d",&n,&x)){
        printf("%I64d\n",phi(n+x+1));
    }
    return 0;
}
View Code

 

posted @ 2015-12-12 22:24  __560  阅读(205)  评论(0编辑  收藏  举报