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

NOIP模拟5

时间:2017-09-10 22:51:21      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:ble   algorithm   cli   open   highlight   16px   for   getch   scan   

 期望得分:100+100+100=300

实际得分:72+12+0=84

 

 T1  [CQOI2009]中位数图

令c[i]表示前i个数中,比d大的数与比d小的数的差,那么如果c[l]=c[r],则[l+1,r]满足条件

技术分享
#include<cstdio>
#include<iostream>
using namespace std;
const int N=1e7;
int c[N*2],g[N];
void read(int &x)
{
    x=0; char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) { x=x*10+c-0; c=getchar();}
}
int main()
{
    
    int n,d,x,now=0,pos;
    long long ans=0;
    bool ok=false;
    read(n); read(d);
    c[n]=1;
    for(int i=1;i<=n;i++)
    {
        read(x);
        if(x<d) now--;
        else if(x>d) now++;
        if(x==d) ok=true,pos=i; 
        if(!ok) c[now+n]++;
        else g[i]=now;
    }
    for(int i=pos;i<=n;i++) ans+=c[g[i]+n];
    printf("%lld",ans);
}
View Code

 

T2  #515. 「LibreOJ β Round #2」贪心只能过样例

dp[i][j] 表示到第i个数,能否凑出j

枚举第i个数能填的数v

dp[i][j]=dp[i-1][j-v*v]

bitset优化

技术分享
#include<bitset>
#include<cstdio>
using namespace std;
const int MAXN=1000001;
bitset<MAXN>b[101];
int main()
{
    //freopen("kinds.in","r",stdin);
    //freopen("kinds.out","w",stdout);
    int n,l,r;
    scanf("%d",&n);
    b[0]^=1;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&l,&r);
        for(int j=l;j<=r;j++) b[i]|=b[i-1]<<(j*j);
    }
    printf("%d",b[n].count());
}
View Code

 

T3

按截距排序之后区间DP

 

#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define N 2001
using namespace std;
void read(int &x)
{
	x=0; int f=1; char c=getchar();
	while(!isdigit(c)) { if(c==‘-‘) f=-1; c=getchar(); }
	while(isdigit(c)) { x=x*10+c-‘0‘; c=getchar();}
	x*=f;
}
struct node
{
	int x,y,v,c,cnt;
	double b;
}e[N];
double k;
const double pi=3.1415926;
const double eps=1e-12;
double dp[N];
double prec[N],prev[N];
int s[N];
double cal(int i)
{
	return e[i].y-k*e[i].x;
}
bool cmp(node p,node q)
{
	return p.b<q.b;
}
int main()
{
	//freopen("yuuka.in","r",stdin);
	//freopen("yuuka.out","w",stdout);
	int n,kk;
	read(n);
	for(int i=1;i<=n;i++) read(e[i].x),read(e[i].y),read(e[i].v),read(e[i].c);
	read(kk);
	if(kk)
	{
		k=tan(pi*kk/180);
		for(int i=1;i<=n;i++) e[i].b=cal(i),e[i].cnt=1;
	}
	else for(int i=1;i<=n;i++) e[i].b=e[i].y,e[i].cnt=1;
	sort(e+1,e+n+1,cmp);
	int tot=1; 
	for(int i=2;i<=n;i++) 
		if(fabs(e[i].b-e[i-1].b)<eps) e[tot].v+=e[i].v,e[tot].c+=e[i].c,e[tot].cnt+=e[i].cnt;
		else e[++tot]=e[i]; 
	for(int i=1;i<=tot;i++) s[i]=s[i-1]+e[i].cnt,prec[i]=prec[i-1]+e[i].c,prev[i]=prev[i-1]+e[i].v;
	dp[1]=e[1].v*e[1].c*1.0/e[1].cnt; 
	for(int i=2;i<=tot;i++)
		for(int j=0;j<i;j++)
			dp[i]=max(dp[i],dp[j]+(prec[i]-prec[j])*(prev[i]-prev[j])*1.0/(s[i]-s[j]));
	printf("%.3lf",dp[tot]);
//	for(int i=1;i<=tot;i++) printf("%.3lf\n",dp[i]);
}

  

NOIP模拟5

标签:ble   algorithm   cli   open   highlight   16px   for   getch   scan   

原文地址:http://www.cnblogs.com/TheRoadToTheGold/p/7502586.html

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