【JLOI2013】T1、T2、T3 Bzoj3190~3192

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Elemmir/article/details/51089670

T1: 赛车 Bzoj3190

画个s-t图像,写个水平可见直线,注意只维护x>=0的部分。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<stack>
using namespace std;
const int maxn = 10005;
int n;
struct line{
	int a,b;int id;
}L[maxn];
bool cmp(line x,line y){return x.a<y.a || (x.a==y.a && x.b>y.b);}
bool ans[maxn];
int Ans[maxn];
stack<double>sta1;stack<line>sta2;
double cross(line x,line y){return (y.b-x.b)*1.0/(x.a-y.a);}
int main(){
	freopen("race.in","r",stdin);
	freopen("race.out","w",stdout);
	scanf("%d",&n);
	int maxb=-100000;
	for(int i=1;i<=n;i++){scanf("%d",&L[i].b);L[i].id=i;maxb=max(maxb,L[i].b);}
	for(int i=1;i<=n;i++){scanf("%d",&L[i].a);if(L[i].b==maxb)ans[i]=1;}
	sort(L+1,L+1+n,cmp);
	sta1.push(0);sta2.push(L[1]);
	for(int i=2;i<=n;i++){
		if(L[i].a==L[i-1].a)continue;
		while(!sta2.empty() && cross(L[i],sta2.top())<sta1.top())sta1.pop(),sta2.pop();
		if(!sta2.empty())sta1.push(cross(L[i],sta2.top()));else sta1.push(0);
		sta2.push(L[i]);
	}
	int cnt=0;
	while(!sta2.empty()){ans[sta2.top().id]=1;sta2.pop();}
	for(int i=1;i<=n;i++)if(L[i].a==L[i-1].a && L[i].b==L[i-1].b)ans[L[i].id]=ans[L[i-1].id];
	int t=0;
	for(int i=1;i<=n;i++)if(ans[i])Ans[++t]=i;
	printf("%d\n",t);
	for(int i=1;i<t;i++)printf("%d ",Ans[i]);printf("%d\n",Ans[t]);
}
/*
4
1 1 0 0
15 16 10 20
*/


T2:卡牌游戏Bzoj3191

是谁不重要,重要的是和庄家的距离,用f[i][j]表示还剩i个人时,从庄家开始数第j个人胜率,枚举所有状态,f[i][j]由f[i-1][*]转移即可

#include<bits/stdc++.h>
using namespace std;
#define MADOKA main
const int maxn = 55;
int a[maxn];
int n,m;
double f[maxn][maxn];
int MADOKA(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d",&a[i]);
	f[1][1]=1;
	for(int i=2;i<=n;i++)for(int j=1;j<=i;j++)for(int k=1;k<=m;k++){
		int tmp=a[k]%i;
		if(tmp==0)tmp=i;if(tmp==j)continue;
		if(tmp>j)tmp=i+j-tmp;else tmp=j-tmp;
		f[i][j]+=f[i-1][tmp]*1.0/m;
	}
	for(int i=1;i<n;i++)printf("%.2lf%% ",f[n][i]*100.0);
	printf("%.2lf%%\n",f[n][n]*100.0);
}


T3:删除物品Bzoj3192

如图:


#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;
#define LL long long
struct node{
	int k,p;
}a[maxn];
int n1,n2,n;
LL ans=0;
bool cmp(node a,node b){
	return a.k>b.k;
}
LL c[maxn];
#define lowbit(x) (x&-x)
void add(int pos,int d){ for(int	i=pos;i<=n;i+=lowbit(i))c[i]+=d; }
LL query(int pos){ LL ret=0;for(int i=pos;i>0;i-=lowbit(i))ret+=c[i];return ret; }
LL query(int pos1,int pos2){ int ret; if(pos1>pos2)ret=0; else ret=query(pos2)-query(pos1-1); return ret; }
int main(){
	freopen("remove.in","r",stdin);
	freopen("remove.out","w",stdout);
	scanf("%d%d",&n1,&n2);
	n=n1+n2;
	for(int i=1;i<=n1;i++){
		scanf("%d",&a[i].k);a[i].p=n1-i+1;
	}
	for(int i=n1+1;i<=n;i++){
		scanf("%d",&a[i].k);a[i].p=i;
	}
	sort(a+1,a+1+n,cmp);
	LL P=n1;
	for(int i=1;i<=n;i++){
		int x=a[i].p;
		if(x < P)ans+=(LL)P-x-query(x+1,P),P=x;
		else if(x>P) ans+=(LL)x-1-P-query(P+1,x-1),P=x-1;
		add(x,1);
	}
	cout<<ans<<endl;
}



阅读更多
换一批

select T1,T2,T3合并

06-18

这段代码运行的结果会出两行 并没有实现合并 请教过的问题 rnrnrnlm = PADL(YEAR(DATE()),4) + PADL( INT(6),2,'0') rnrnm.lm = yy rnSelect 货物名称,规格,单位, Sum(数量) As 数量,sum(金额) AS 金额,avg(iif(单价>0,单价,0)) as 单价 From 入库表 ; rnWhere LEFT(dtos(日期),6)==PADL(YEAR(DATE()),4) + PADL( yy,2,'0') GROUP By 货物名称,规格,单位 ; rnOrder by 货物名称 Into Cursor t1 rnSelect 货物名称,规格,单位, Sum(数量) As 数量,sum(金额) AS 金额 From 出库表 ; rnWhere LEFT(dtos(日期),6)==PADL(YEAR(DATE()),4) + PADL( yy,2,'0') GROUP By 货物名称,规格,单位 ; rnOrder by 货物名称 Into Cursor t2 rnSelect 货物名称,规格,单位, Sum(销售数量) As 数量,sum(销售成本) AS 金额 From 销售表 ; rnWhere LEFT(dtos(日期),6)==PADL(YEAR(DATE()),4) + PADL( yy,2,'0') GROUP By 货物名称,规格,单位 ; rnOrder by 货物名称 Into Cursor t3 rnSelect ; rnNVL( t1.货物名称, t2.货物名称 ) AS 货物名称, ; rnNVL( t1.规格, t2.规格 ) AS 规格, ; rnNVL( t1.单位, t2.单位 ) AS 单位, ; rnNVL( t1.金额, 0 ) - NVL( t2.金额,0 ) AS 余额, ; rnNVL( t1.数量, 0 ) - NVL( t2.数量,0 ) AS 余量, ; rnNVL( t1.数量, 0 ) AS 入库量, ; rnNVL( t1.单价, 0 ) AS 单价, ; rnNVL( t1.金额, 0 ) AS 入库额, ; rnNVL( t3.数量, 0 ) AS 销售量, ; rnNVL( t3.金额, 0 ) AS 销售额 ; rnFROM t1 ; rnFULL OUTER JOIN t2 ; rnON t1.货物名称 = t2.货物名称 AND t1.规格 = t2.规格 AND t1.单位 = t2.单位 ; rnFULL OUTER JOIN t3 ; rnON t1.货物名称 = t3.货物名称 AND t1.规格 = t3.规格 AND t1.单位 = t3.单位 ; rnOrder by t1.货物名称 Into Cursor m1 rnbrow rnrn这段代码运行的结果会出两行 并没有实现合并 请教过的问题

没有更多推荐了,返回首页