https://www.nowcoder.com/acm/contest/143#question
不知不觉已经打完了一半的多校,水平还是很菜啊
过了5题,rank96
J:枚举+简单逻辑
solved by sdn and wyq
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
int n,p2,p3,p6;
long long ans=0;
scanf("%d%d%d",&n,&p2,&p3);
if(3*p2<2*p3)p6=3*p2;
else p6=2*p3;
ans+=(long long)(n/6)*(long long)p6;
if(n%6==0)printf("%lld\n",ans);
if(n%6==1)printf("%lld\n",ans+(long long)min(p2,p3));
if(n%6==2)printf("%lld\n",ans+(long long)min(p2,p3));
if(n%6==3)printf("%lld\n",ans+(long long)min(p2*2,p3));
if(n%6==4)printf("%lld\n",ans+(long long)min(p2*2,p3*2));
if(n%6==5)printf("%lld\n",ans+(long long)min(p2*3,p3*2));
return 0;
}
G:简单题
solved by lyy
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n,c;
int main()
{
cin>>c>>n;
ll ans;
int x=n/c;
if (x==1) cout<<(ll)c*c<<endl;
else if (x==0) cout<<-1<<endl;
else
{
ans=(ll)x*(x-1)*c*c;
cout<<ans<<endl;
}
return 0;
}
E:
solved by wyq
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _clr(x) memset(x,-1,sizeof(int)*105)
#define inf 10000000
int ok[105];
int a[105][5];
int b[105][5];
int mat[105][105];
int match1[105],match2[105];
int m,n;
int kuhn_munkras()
{
int s[105],t[105],l1[105],l2[105],p,q,ret=0,i,j,k;
for(i=0;i<m;i++)
{
for(l1[i]=-inf,j=0;j<n;j++)
{
l1[i]=mat[i][j]>l1[i]?mat[i][j]:l1[i];
//printf("%d %d\n",l1[i],mat[i][j]);
}
if(l1[i]==-inf)return -1;
}
for(i=0;i<n;l2[i++]=0);
for(_clr(match1),_clr(match2),i=0;i<m;i++)
{
for(_clr(t),s[p=q=0]=i;p<=q&&match1[i]<0;p++)
for(k=s[p],j=0;j<n&&match1[i]<0;j++)
if(l1[k]+l2[j]==mat[k][j]&&t[j]<0)
{
s[++q]=match2[j],t[j]=k;
if(s[q]<0)
for(p=j;p>=0;j=p)
match2[j]=k=t[j],p=match1[k],match1[k]=j;
}
if(match1[i]<0)
{
for(i--,p=inf,k=0;k<=q;k++)
for(j=0;j<n;j++)
if(t[j]<0&&l1[s[k]]+l2[j]-mat[s[k]][j]<p)
p=l1[s[k]]+l2[j]-mat[s[k]][j];
for(j=0;j<n;l2[j]+=t[j]<0?0:p,j++);
for(k=0;k<=q;l1[s[k++]]-=p);
}
}
for(i=0;i<m;i++)
{
//if(match1[i]<0)return -1;
//if(mat[i][match1[i]]<=-inf)return -1;
ret+=mat[i][match1[i]];
}
return ret;
}
int main()
{
memset(mat,0,sizeof(mat));
int i,j,k;
scanf("%d",&n);
m=n;
for(i=1;i<=n;i++)
{
for(j=1;j<=4;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=4;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
memset(ok,0,sizeof(ok));
for(k=1;k<=4;k++)
{
ok[a[i+1][k]]=1;
}
for(k=1;k<=4;k++)
{
if(ok[b[j+1][k]]==0)mat[i][j]--;
}
}
}
/*for(i=0;i<n;i++)
for(j=0;j<n;j++)
printf("%d ",mat[i][j]);
*/
printf("%d\n",-kuhn_munkras());
return 0;
}
A:二分答案,然后排序完依次取即可,题解给的时间复杂度是O(nlogn),感觉有点问题啊,没算二分的log啊
solved by lyy
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n,k;
double m;
struct st
{
double s;
double c;
}a[100005];
bool cmp(st a,st b)
{
return (a.c-m)*a.s>(b.c-m)*b.s;
}
bool go()
{
sort(a+1,a+n+1,cmp);
double c=0;
double s=0;
for (int i=1;i<=n-k;i++)
{
c+=a[i].c*a[i].s;
s+=a[i].s;
}
if (c/s>m) return true;
else return false;
}
double find()
{
double l=1,r=1e3;
while (r-l>=1e-7)
{
m=(l+r)/2;
if (go()) l=m;
else r=m;
}
return (l+r)/2;
}
int main()
{
//freopen("in.txt","r",stdin);
scanf("%d%d",&n,&k);
for (int i=1;i<=n;i++)
{
scanf("%lf",&a[i].s);
}
for (int i=1;i<=n;i++)
{
scanf("%lf",&a[i].c);
}
printf("%.8f\n",find());
return 0;
}
F:推了个公式,然后线段树维护即可
solved by lyy
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=998244353;
//线段树模板
#define maxn 100007 //元素总个数
ll sum[maxn<<2];//sum求和,add为懒惰标记
ll a[maxn];//存原数组数据下标[1,n]
int n,m;
int p[maxn];
int d[maxn];
struct st
{
int id;
int data;
int num;
}b[maxn];
bool cmp1(st a,st b)
{
return a.data<b.data;
}
bool cmp2(st a,st b)
{
return a.id<b.id;
}
long long inv(long long a,long long m)
{
if(a == 1)return 1;
return inv(m%a,m)*(m-m/a)%m;
}
//pushup函数更新节点信息 ,这里是求和
void pushup(int rt)
{
sum[rt]=sum[rt<<1]*sum[rt<<1|1]%mod;
}
//Build函数建树
void build(int l,int r,int rt)
{
if(l==r) //若到达叶节点
{
sum[rt]=a[l];//储存数组值
return;
}
int m=(l+r)>>1;
//左右递归
build(l,m,rt<<1);
build(m+1,r,rt<<1|1);
//更新信息
pushup(rt);
}
void update(int L,ll c,int l,int r,int rt)
{
if(l==r) //到叶节点,修改
{
sum[rt]=sum[rt]*(1-c+mod)%mod;
return;
}
int m=(l+r)>>1;
//根据条件判断往左子树调用还是往右
if (L<=m) update(L,c,l,m,rt<<1);
else update(L,c,m+1,r,rt<<1|1);
pushup(rt);//子节点更新了,所以本节点也需要更新信息
}
ll query(int L,int R,int l,int r,int rt)
{
if(L<=l && r<=R)//在区间内,直接返回
{
return sum[rt];
}
int m=(l+r)>>1;
//累计答案
ll ans=1;
if(L <= m) ans=ans*query(L,R,l,m,rt<<1)%mod;
if(R > m) ans=ans*query(L,R,m+1,r,rt<<1|1)%mod;
return ans;
}
int main()
{
//freopen("in.txt","r",stdin);
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%d%d",&p[i],&d[i]);
p[i]=p[i]*inv(100,mod)%mod;
b[i].data=d[i];
b[i].id=i;
}
m=0;
sort(b+1,b+n+1,cmp1);
for (int i=1;i<=n;i++)
{
b[i].num=++m;
while (i<n && b[i+1].data==b[i].data)
{
i++;
b[i].num=m;
}
}
sort(b+1,b+n+1,cmp2);
for (int i=1;i<=n;i++)
{
d[i]=b[i].num;
}
for (int i=1;i<=m;i++)
{
a[i]=1;
}
build(1,m,1);
ll ans=0;
for (int i=1;i<=n;i++)
{
//ans=ans+p[i]*PI(1-p[i])
ll x=query(d[i],m,1,m,1);
ans=(ans+p[i]*x)%mod;
update(d[i],p[i],1,m,1);
//cout<<ans<<endl;
}
printf("%lld\n",ans);
return 0;
}