bestcoder 20 A,B
来源:互联网 发布:体育网络电视 编辑:程序博客网 时间:2024/05/19 09:03
今天做了两场比赛,一场是现场赛,一场bc,bc的第一题感觉超级水,可是就是不过,赛后才发现原来是自己看错题意了。第二题线段数没写出来,赛后写了一下,发现pushdown写错了,尼玛,还是做的题少呀。。。。。。
A题就是输出选票最多的并且id最小的 i的id就是i
比如 5 1 3 3 2 2 输出是2
就一直卡在这了
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[1100];int b[1100];int main(){ int t; int n; while(scanf("%d",&t)==1){ while(t--){ memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&a[i]); b[a[i]]++; } int maxx=-1; int k; for(int i=1;i<=n;i++) if(b[i]>maxx){ k=i; maxx=b[i]; b[i]=0; } printf("%d\n",k); } }}
b题就是成端更新后求最大值。。。
简单hash一下就好
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define maxx 200010#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1int sum[maxx<<2];int num[maxx<<2];int cnt;int add[maxx<<2];int hash[maxx<<2];int a[maxx],b[maxx];void pushup(int rt){ sum[rt]=max(sum[rt<<1|1],sum[rt<<1]);}void pushdown(int rt){ if(add[rt]){ add[rt<<1]+=add[rt]; add[rt<<1|1]+=add[rt]; sum[rt<<1]+=add[rt]; sum[rt<<1|1]+=add[rt]; add[rt]=0; }}void update(int L,int R ,int c,int l,int r,int rt){ if(L<=l&&R>=r){ add[rt]+=c; sum[rt]+=c; return ; } pushdown(rt); int m=(l+r)>>1; if(L<=m) update(L,R,c,lson); if(R>m) update(L,R,c,rson); pushup(rt);}int cheak(int aa,int nn,int num[]){ int l=0,r=nn-1; while(l<=r){ int m=(l+r)>>1; if(num[m]==aa) return m; if(num[m]<aa) l=m+1; else r=m; } return -1;}int main(){ int T,n; scanf("%d",&T); while(T--){ scanf("%d",&n); int m=0; for(int i=0;i<n;i++){ scanf("%d%d",&a[i],&b[i]); num[m++]=a[i]; num[m++]=b[i]; } sort(num,num+m); // for(int i=0;i<m;i++) // printf("%d %d\n",i,num[i]); int h=1; for(int i=1;i<m;i++){ if(num[i]!=num[i-1]) num[h++]=num[i]; } //puts("--------------"); // for(int i=0;i<h;i++) // printf("%d %d\n",i,num[i]); memset(sum,0,sizeof(sum)); memset(hash,0,sizeof(hash)); memset(add,0,sizeof(add)); for(int i=0;i<n;i++){ int l=cheak(a[i],h,num); int r=cheak(b[i],h,num); update(l,r,1,0,h,1); } printf("%d\n",sum[1]); }}
0 0
- bestcoder 20 A,B
- BestCoder Round #3 A,B
- BestCoder Round #25 A,B
- BestCoder #85 A,B,C
- bestcoder 86 A B C
- BestCoder Round #92 A+B
- BestCoder Round #20 解题报告 A.B.C.
- BestCoder Round #20 B
- BestCoder Round #7-A,B,C
- BestCoder Round #8 A,B,C
- BestCoder Round #29 A,B,C
- BestCoder Round #40 A B C
- BestCoder Round #41 -- (A,B)
- BestCoder Round #41 A B C
- BestCoder Round #78 (div.2) A B
- BestCoder Round #82 (div.2) A B
- BestCoder Round #90 A+B题解!
- BestCoder Round #20 A
- 自动跳转网站手机版脚本
- AES加密和解密实用版
- tomcat上json数据乱码问题的解决
- 第14周项目1-折腾二维数组
- :输入10个整数,保存在一个数组中,在数组中查找某个数,给出是否找到的信息。如果找到了,要求输出该数在数组中所处的位置;如果找不到,输出“没有找到!
- bestcoder 20 A,B
- poj解题报告——2126
- 最常用的Windows、Linux网络命令总结
- Transact-SQL编程
- 离散数学 偏序关系中盖住关系的求取及格论中有补格的判定
- 详解μC/OS-II软件定时器入门使用方法
- win8.1 UEFI模式下安装ubuntu遇到的问题
- 详解Jquery.form.js
- [@Controller]1 基于@注释的控制器配置