# 4.9-4.15练习

1.Codeforces Round #474 C. Subsequence Counting

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
#define maxn 10050
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
typedef long long ll;

int x,d;
vector<ll>v;

int main()
{
scanf("%d%d",&x,&d);
ll cnt=1;
for(int i=31;i>=0;i--)
{
while(x>=(1<<i)-1)
{
x-=(1<<i)-1;
for(int j=0;j<i;j++)
v.push_back(cnt);
cnt+=(d+1);
if(x==0)break;
}
if(x==0)break;
}
printf("%d\n",v.size());
for(int i=0;i<v.size();i++)
{
printf(i==0?"%I64d":" %I64d",v[i]);
}
printf("\n");
return 0;
}

2. Codeforces Educational Round #42 D. Merge Equal

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
#define maxn 300050
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
typedef long long ll;

int n;
ll a[maxn];
struct node
{
ll w;
int p;
node(ll a=0,int b=0){w=a,p=b;}
bool friend operator < (const node x,const node y)
{
return x.w>y.w||(x.w==y.w&&x.p>y.p);
}
};
priority_queue<node>q;

int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%I64d",&a[i]);
q.push(node(a[i],i));
}
while(!q.empty())
{
node u=q.top();
q.pop();
if(q.empty())break;
node v=q.top();
q.pop();
if(u.w!=v.w)
{
q.push(v);
continue;
}
a[u.p]=0;
a[v.p]=2LL*v.w;
q.push(node(2LL*v.w,v.p));
}
int ans=0;
for(int i=1;i<=n;i++)
{
if(a[i])ans++;
}
printf("%d\n",ans);
int num=0;
for(int i=1;i<=n;i++)
{
if(a[i])
printf(num==ans-1?"%I64d\n":"%I64d ",a[i]),num++;
}
return 0;
}

3. CHD4.14校赛

B. Happy Running

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
#define maxn 160
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
typedef long long ll;

int t;
double k,x;

int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf",&k,&x);
double ans;
if(k>=2*x)ans=0.0;
else if(k<=x)ans=1-k*k/(2*x*x);
else ans=((2*x-k)*(2*x-k))/(2*x*x);
printf("%.2lf\n",ans);
}
return 0;
}

D. Dragon Ball Super

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
#define maxm 400050
#define maxn 100050
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
typedef long long ll;

int t,n,m,k,p,q,pre;
struct node
{
int x,y,id;
}b[maxn];
int c[maxm],ans[maxn],a[maxn];
map<int,int>ma;

bool cmp(node a,node b)
{
return a.y<b.y;
}

int finding(int x)
{
int r=x;
while(a[r]!=r)
r=a[r];
int i=x,j;
while(i!=r)
{
j=a[i];
a[i]=r;
i=j;
}
return r;
}

int lowbit(int x)
{
return x&(-x);
}

void update(int x,int val)
{
int tmp=x;
while(tmp<=n)
{
c[tmp]+=val;
tmp+=lowbit(tmp);
}
}

int sum(int x)
{
int tmp=x;
int sum=0;
while(tmp>0)
{
sum+=c[tmp];
tmp-=lowbit(tmp);
}
return sum;
}

int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
a[i]=i;
for(int i=0;i<k;i++)
{
scanf("%d%d",&p,&q);
//if(p>q)swap(p,q);
int fp=finding(p);
int fq=finding(q);
//if(fp!=fq)a[fp]=fq;
if(fp>fq)
a[fp]=fq;
else
a[fq]=fp;

}
for(int i=1;i<=n;i++)
{
int tmp=finding(i);
}

scanf("%d",&m);
for(int i=0;i<m;i++)
{
scanf("%d%d",&b[i].x,&b[i].y);
b[i].id=i;
}
sort(b,b+m,cmp);
pre=1;
memset(c,0,sizeof(c));
ma.clear();
for(int i=0;i<m;i++)
{
for(int j=pre;j<=b[i].y;j++)
{
if(ma.find(a[j])==ma.end())
update(j,1);
else
{
update(ma[a[j]],-1);
update(j,1);
}
ma[a[j]]=j;
}
ans[b[i].id]=sum(b[i].y)-sum(b[i].x-1);
pre=b[i].y+1;
}
for(int i=0;i<m;i++)
printf("%d\n",ans[i]);
}
return 0;
}

H. Transfer Window

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<iostream>
#include<algorithm>
#define maxn 2005
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
typedef long long ll;

int t,n,m,p;
int dp[maxn];
int a[maxn],b[maxn];

int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%d",&a[i],&b[i]);
scanf("%d",&m);
for(int i=1;i<=m;i++)
scanf("%d%d",&a[i+n],&b[i+n]);
scanf("%d",&p);
for(int i=1;i<=n;i++)p+=b[i];
memset(dp,0,sizeof(dp));
for(int i=1;i<=n+m;i++)
{
for(int j=p;j>=b[i];j--)
dp[j]=max(dp[j],dp[j-b[i]]+a[i]);
}
int ans=0;
for(int i=1;i<=p;i++)
ans=max(ans,dp[i]);
printf("%d\n",ans);
}
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120