转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

who is the best?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
There are N people want to choose the best person. Each person select the best person ai, .John wants to know that who received the most number of votes.
 



Input
The first line contains a single integer T(1≤T≤50),indicating the number of test cases.
Each test case begins with an integer N(1≤N≤100),indicating the number of person.
Next N lines contains an integer ai(1≤ai≤N).
 



Output
For each case, output an integer means who is the best person. If there are multiple answers, print the minimum index.
 



Sample Input
2
10
1
2
3
4
5
6
7
8
9
10
5
3
3
3
3
3
 
Sample Output
1
3

题意:求出现次数最多的数,若有多个数,则输出最小的一个

水题,随便搞

 #include<iostream>
#include <cstring>
using namespace std;
int a[];
int main()
{
ios::sync_with_stdio(false);
int t;
cin>>t;
int n;
memset(a,,sizeof(a));
while(t--)
{
int n;
cin>>n;
int k;
int maxx=;
memset(a,,sizeof(a));
int ans=;
for(int i=;i<n;i++)
{
cin>>k;
a[k]++;
if(a[k]>=maxx)
{
if(a[k]==maxx)
{
ans=min(ans,k);
}
else
{
ans=k;
}
maxx=a[k];
}
}
cout<<ans<<endl;
}
return ;
}

代码君

lines

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
John
has several lines. The lines are covered on the X axis. Let A is a
point which is covered by the most lines. John wants to know how many
lines cover A.
 
Input
The first line contains a single integer T(1≤T≤100)(the data for N>100 less than 11 cases),indicating the number of test cases.
Each test case begins with an integer N(1≤N≤105),indicating the number of lines.
Next N lines contains two integers Xi and Yi(1≤Xi≤Yi≤109),describing a line.
 
Output
For each case, output an integer means how many lines cover A.
 
Sample Input
2
5
1 2
2 2
2 4
3 4
5 1000
5
1 1
2 2
3 3
4 4
5 5
 
Sample Output
3
1

题意:有n条线段,求被覆盖到次数最多的点的次数

分析:

1.可以转化成求前缀和最大的问题:将区间改成左闭右开(即右端点加1),排序,从左往右遍历,若为左端点则加一,右端点则减一。

2.线段树,离散化一下,然后区间更新,单点查询。

 #include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<int,int> PII;
PII a[];
int main()
{
ios::sync_with_stdio(false);
int t;
//freopen("in.in","r",stdin);
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
n=n*;
for(int i=;i<n;i++)
{
scanf("%d",&a[i].first);
a[i].second=;
scanf("%d",&a[++i].first);
a[i].first++;
a[i].second=-;
}
sort(a,a+n);
int ans=;
int k=;
for(int i=;i<n;i++)
{
k=k+a[i].second;
ans=max(k,ans);
}
printf("%d\n",ans);
}
}

代码君

magic balls

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
The town of W has N people. Each person takes two magic balls A and B every day. Each ball has the volume ai and bi.
People often stand together. The wizard will find the longest
increasing subsequence in the ball A. The wizard has M energy. Each
point of energy can change the two balls’ volume.(swap(ai,bi)).The
wizard wants to know how to make the longest increasing subsequence and
the energy is not negative in last. In order to simplify the problem,
you only need to output how long the longest increasing subsequence is.
 
Input
The first line contains a single integer T(1≤T≤20)(the data for N>100 less than 6 cases), indicating the number of test cases.
Each test case begins with two integer N(1≤N≤1000) and M(0≤M≤1000),indicating the number of people and the number of the wizard’s energy. Next N lines contains two integer ai and bi(1≤ai,bi≤109),indicating the balls’ volume.
 
Output
For each case, output an integer means how long the longest increasing subsequence is.
 
Sample Input
2
5 3
5 1
4 2
3 1
2 4
3 1
5 4
5 1
4 2
3 1
2 4
3 1
 
Sample Output
4
4

题意:有两组数a,b,另外最多可以对其做m次操作——即swap(a[i],b[i]),问在此情况下a数组最大的LIS长度是多少?

分析:先将数据离散化,然后用m+1个树状数组或者线段树来维护在还剩余j次操作之后到第i个数时的最大的LIS长度。

sad,这道题我用了线段树来维护RMQ,一直TLE,最后在参考了邝巨巨的情况下才过了的。

^_^通过这道题目知道了如何运用树状数组来维护RMQ,之前只会用线段树搞搞。

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
struct BIT
{
int bit[];
int n;
int init(int size)
{
n=size;
for(int i=;i<n;i++)bit[i]=;
}
int query(int i)
{
int s=;
while(i>)
{
s=max(s,bit[i]);
i-=i&-i;
}
return s;
}
int update(int i,int x)
{
while(i<=n)
{
bit[i]=max(x,bit[i]);
i+=i&-i;
}
}
}bt[];
int a[],b[],c[];
int main()
{
//ios::sync_with_stdio(false);
int t;
//freopen("in.in","r",stdin);
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
int cnt=;
for(int i=;i<n;i++)
{
scanf("%d%d",&a[i],&b[i]);
c[++cnt]=a[i];
c[++cnt]=b[i];
}
sort(c+,c+cnt+);
cnt=unique(c+,c+cnt+)-c-;
for(int i=;i<n;i++)
{
a[i]=lower_bound(c+,c+cnt+,a[i])-c;
b[i]=lower_bound(c+,c+cnt+,b[i])-c;
}
int ans=;
for(int i=;i<=m;i++)bt[i].init(cnt);
for(int i=;i<n;i++)
{
for(int j=;j<=m;j++)
{
int x=bt[j].query(a[i]-)+;
bt[j].update(a[i],x);
ans=max(ans,x);
if(j<m)
{
x=bt[j+].query(b[i]-)+;
bt[j].update(b[i],x);
ans=max(ans,x);
}
}
}
cout<<ans<<endl; } return ;
}

代码君

D题

目前还不会,不会cdq分治。。。

BestCoder Round #20 部分题解(A,B,C)(hdu5123,5124,5125)的更多相关文章

  1. BestCoder Round #86 部分题解

    Price List 题意: 有n件商品,每天只能买一件,并且会记录账本,问有多少次一定记多了? 题解: 就是求和,最后如果大于和就输出1,否则0. 代码: #include <bits/std ...

  2. hdu 5066 Harry And Physical Teacher(Bestcoder Round #14)

    Harry And Physical Teacher Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  3. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  4. BestCoder Round #11 (Div. 2) 题解

    HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  5. BestCoder Round #90 A+B题解!

    BestCoder Round #90 A  Kblack loves flag 题意有点迷不造思路很简单但不造怎么求随机数,纠结了一会后直接粘上题目所给的代码稍加修改A了. const int _K ...

  6. BestCoder Round #11 (Div. 2) 前三题题解

    题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...

  7. [BestCoder Round #3] hdu 4908 BestCoder Sequence (计数)

    BestCoder Sequence Problem Description Mr Potato is a coder. Mr Potato is the BestCoder. One night, ...

  8. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

  9. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

随机推荐

  1. html5 新属性

    <p contenteditable="true">这是一段可编辑的段落.请试着编辑该文本.</p> <input id="email&qu ...

  2. Python正则匹配字母大小写不敏感在读xml中的应用

    需要解决的问题:要匹配字符串,字符串中字母的大小写不确定,如何匹配? 问题出现之前是使用字符串比较的方式,比如要匹配'abc',则用语句: if s == 'abc':#s为需要匹配的字符串 prin ...

  3. 使用pip install 或者easy_install安装Python的各种包出现cc failed with exit status 1

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  4. Servlet接收JSP参数乱码问题解决办法

    转自:http://lavasoft.blog.51cto.com/62575/274527/   环境: apache-tomcat-6.0.24.zip jdk1.6.0_16 WindosXP ...

  5. Ceph的Block分析

    一个块是一个连续的字节序列(例如一个512字节的连续数据是一个块).基于块的存储接口通常是旋转介质,例如磁盘.光盘.软盘等.块设备接口的普及使得可以用虚拟的块设备成为和大容量数据存储系统交互的接口,如 ...

  6. Effective Java2读书笔记-类和接口(三)

    第17条:要么为继承而设计,并提供文档说明,要么就禁止继承 第18条:接口优于抽象类 这两条中,提到了一个很重要的概念骨架实现.也就是说,抽象类实现接口的形式.这样的好处是,接口本来不能提供默认的实现 ...

  7. (转)Autotrace工具使用——小工具,大用场

    监控SQL语句,获取执行计划和执行成本,是每个Oracle开发人员与DBA所必须具备的能力之一. 当Oracle彻底进入CBO时代,我们面对一种全新的局面.一方面,基于数据统计量的CBO优化器,让SQ ...

  8. Codeforces 577B Modulo Sum

    http://codeforces.com/problemset/problem/577/B 题意:有n个数,求有无一个子序列满足和是m的倍数 思路:用模下的背包做,发现n是十的六次方级别,但是有个神 ...

  9. Keil C51 知识点

    第一节 Keil C51扩展关键字     深入理解并应用C51对标准ANSIC的扩展是学习C51的关键之一.因为大多数扩展功能都是直接针对8051系列CPU硬件的.大致有以下8类: 8051存储类型 ...

  10. 设置EntityFramework 在开发时自动更新数据库

    1. NuGet 下载EntityFramework. 2. 定义Context 和 打开NuGet 命令 执行 Enable-Migrations , Libaray.DAL.Migrations. ...