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