码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces #pi

时间:2015-08-06 07:04:42      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

codeforces #pi

A,B题:水题,略。

C题:求一个序列中形成以k为公比项数为3的等比数列的种类数。考虑中间项b,统计b/k在前面出现的次数pre[b/k]和b*k在后面出现的次数suf[b*k],相乘。统计pre可以从前往后扫,统计suf则用all减去pre即可。

技术分享
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<math.h>
#include<cctype>
#define ll long long
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define REPP(i,a,b,t) for(int (i)=(a);(i)<=(b);(i)+=(t))
#define rep(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define repp(i,a,b,t) for(int (i)=(a);(i)>=(b);(i)-=(t))
#define PII pair<int,int>
#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define RI(x) scanf("%d",&(x))
#define RII(x,y) scanf("%d%d",&(x),&(y))
#define RIII(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
#define DRI(x) int (x);scanf("%d",&(x))
#define DRII(x,y) int (x),(y);scanf("%d%d",&(x),&(y))
#define DRIII(x,y,z) int (x),(y),(z);scanf("%d%d%d",&(x),&(y),&(z))
#define RS(x) scanf("%s",x)
#define RSS(x,y) scanf("%s%s",x,y)
#define DRS(x) char x[maxn];scanf("%s",x)
#define DRSS(x,y) char x[maxn],y[maxn];scanf("%s%s",x,y)
#define MS0(a) memset((a),0,sizeof((a)))
#define MS1(a) memset((a),-1,sizeof((a)))
#define MS(a,b) memset((a),(b),sizeof((a)))
#define ALL(v) v.begin(),v.end()
#define SZ(v) (int)(v).size()

using namespace std;

const int maxn=1000100;
const int INF=(1<<29);
const double EPS=0.0000000001;
const double Pi=acos(-1.0);

int n,k;
ll a[maxn];
map<ll,int> all,pre;

int main()
{
    //freopen("in.txt","r",stdin);
    while(~RII(n,k)){
        all.clear();pre.clear();
        REP(i,1,n){
            scanf("%I64d",&a[i]);
            all[a[i]]++;
        }
        ll ans=0;
        REP(i,1,n){
            if(a[i]%k==0){
                ll l=pre[a[i]/k];
                ll r=all[a[i]*k]-pre[a[i]*k];
                if(k==1||a[i]==0) r--;
                ans+=l*r;
            }
            pre[a[i]]++;
        }
        cout<<ans<<endl;
    }
    return 0;
}
View Code

D题:

注意set的二分,s.lower_bound(x),求比x小的数用s.lower_bound(x)-1即可。

技术分享
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<math.h>
#include<cctype>
#define ll long long
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define REPP(i,a,b,t) for(int (i)=(a);(i)<=(b);(i)+=(t))
#define rep(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define repp(i,a,b,t) for(int (i)=(a);(i)>=(b);(i)-=(t))
#define PII pair<int,int>
#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define RI(x) scanf("%d",&(x))
#define RII(x,y) scanf("%d%d",&(x),&(y))
#define RIII(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
#define DRI(x) int (x);scanf("%d",&(x))
#define DRII(x,y) int (x),(y);scanf("%d%d",&(x),&(y))
#define DRIII(x,y,z) int (x),(y),(z);scanf("%d%d%d",&(x),&(y),&(z))
#define RS(x) scanf("%s",x)
#define RSS(x,y) scanf("%s%s",x,y)
#define DRS(x) char x[maxn];scanf("%s",x)
#define DRSS(x,y) char x[maxn],y[maxn];scanf("%s%s",x,y)
#define MS0(a) memset((a),0,sizeof((a)))
#define MS1(a) memset((a),-1,sizeof((a)))
#define MS(a,b) memset((a),(b),sizeof((a)))
#define ALL(v) v.begin(),v.end()
#define SZ(v) (int)(v).size()

using namespace std;

const int maxn=1000100;
const int INF=(1<<29);
const double EPS=0.0000000001;
const double Pi=acos(-1.0);

int n,k,a;
int m;
int b;
set<int> s;
int x,y;

int main()
{
    //freopen("in.txt","r",stdin);
    while(~RIII(n,k,a)){
        RI(m);
        s.clear();
        int sum=(n+1)/(a+1);
        s.insert(0);s.insert(n+1);
        int ans=-1;
        bool flag=0;
        REP(i,1,m){
            RI(b);
            set<int>::iterator it=s.upper_bound(b);
            int y=*it;
            int x=*(--it);
            sum-=(y-x)/(a+1)-(y-b)/(a+1)-(b-x)/(a+1);
            if(sum<k&&!flag) ans=i,flag=1;
            s.insert(b);
        }
        cout<<ans<<endl;
    }
    return 0;
}
View Code

 

codeforces #pi

标签:

原文地址:http://www.cnblogs.com/--560/p/4706317.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!