2014 Benelux Algorithm Programming Contest (BAPC 14)

2014 Benelux Algorithm Programming Contest (BAPC 14)

算5题?嘻嘻

Gym - 101512B Button Bashing

水题

#include<bits/stdc++.h>
using namespace std;
const int maxn=7206;
const int inf=0x3f3f3f3f; 

int t[maxn],d[2*maxn];

int main()
{
    int n,m,T;
    cin>>T;
    while(T--){
        scanf("%d %d",&n,&m);
        for(int i=1;i<=n;i++)
            scanf("%d",t+i);

        queue<int>q;
        pair<int,int> ans=make_pair(inf,inf);
        memset(d,0x3f,sizeof d);
        d[0]=0,q.push(0);

        while(!q.empty()){
            int nd=q.front();
            q.pop();
            if(nd>=m)ans=min(ans,make_pair(nd,d[nd]));
            for(int i=1;i<=n;i++){
                int u=nd+t[i];
                if(u<0)u=0;
                if(u>3600)u=3600;
                if(d[u]==inf)
                    d[u]=d[nd]+1,q.push(u);
            }
        }
        cout<<ans.second<<" "<<ans.first-m<<endl;
    }
    return 0;
}

Gym - 101512E Excellent Engineers

知道树状数组的我哭了起来。
按A维排序,在B处插入C的值,维护区间最小值。查询时看(1~B)的最小值,有比C小的就加一。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=2e5+5;
int n, maxVal;
struct Operation
{
    int a, b, c, w;
    int f;//ans
    bool operator <(const Operation &r)const
    {
        //return a<r.a || (a==r.a&&b<r.b) || (a==r.a&&b==r.b&&c<r.c);
        return (a==r.a&&b==r.b) ? c<r.c : (a==r.a ? b<r.b : a<r.a);
    }
}a[MAXN], t[MAXN];
LL c[MAXN];
inline int lowbit(int x) { return x&-x; }
inline void add(int p, int v) { for(;p<=maxVal;p+=lowbit(p)) c[p]+=v; }
inline LL sum(int p)
{
    LL re=0;
    for(;p;p-=lowbit(p)) re+=c[p];
    return re;
}
int ans[MAXN];
LL rres;
void CDQ(int l, int r)
{
    if(l==r) return;
    int mid=(l+r)>>1;
    CDQ(l, mid);CDQ(mid+1, r);
    int i=l, j=mid+1, p=l;
    while(i<=mid||j<=r)
    {
        if(j>r||(i<=mid&&a[i].b<=a[j].b)) add(a[i].c, a[i].w), t[p++]=a[i++];
        else a[j].w+=sum(a[j].c), t[p++]=a[j++];
    }
    for(int i=l;i<=mid;i++) add(a[i].c, -a[i].w);
    for(int i=l;i<=r;i++) a[i]=t[i];
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
        scanf("%d", &n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i].a),scanf("%d",&a[i].b),scanf("%d",&a[i].c),a[i].w=1;
        sort(a+1, a+1+n);

        int p=1;
        maxVal=MAXN-1;

        rres=0;
        CDQ(1, n);
        for(int i=1;i<=n;i++)
            if(a[i].w==1) rres++;
        printf("%d\n",rres);
    }
    //system("pause");
}

Gym - 101512I Interesting Integers

数学题,at老谭

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

LL f[49];
LL e_gcd(LL a,LL b,LL &x,LL &y)  
{  
    if(b==0
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值