http://acm.hdu.edu.cn/showproblem.php?pid=5131

现场赛第一个题,水题。题意:给水浒英雄排序,按照杀人数大到小,相同按照名字字典序小到大。输出。然后对每个查询的名字,计数有多少人杀人数大于他,输出个数加1,计数有多少人杀人数相同,但名字小,如果没有不输出,否则输出个数加1。

 #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct G{
string name;
int kill;
friend bool operator <(const G a,const G b){
return a.kill>b.kill||(a.kill==b.kill&&a.name<b.name);
}
}g[];
string str;
int main(){
int n,m,id;
while(~scanf("%d",&n),n){
for(int i=;i<n;i++){
cin>>g[i].name>>g[i].kill;
}
sort(g,g+n);
for(int i=;i<n;i++){
cout<<g[i].name<<" "<<g[i].kill<<endl;
}
scanf("%d",&m);
while(m--){
cin>>str;
for(int i=;i<n;i++){
if(str==g[i].name){
id=i;
break;
}
}
int ansa=,ansb=;
for(int i=;i<id;i++){
if(g[i].kill>g[id].kill){
ansa++;
}
else{
ansb++;
}
}
printf("%d",ansa);
if(ansb>){
printf(" %d",ansb);
}
puts("");
}
}
return ;
}

http://acm.hdu.edu.cn/showproblem.php?pid=5137

第二题,最短路。题意:给一个n点m边带权无向图,可以破坏2到n-1号中任意一个,问破坏哪个后1到n的最短路最长。做法:枚举破坏的点,对于每个最短路,求最大值。

 #include<cstdio>
#include<cstring>
#include<queue>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const int inf=0x3f3f3f3f;
bool can[];
class Spfa { ///单源最短路o(2*ME)
typedef int typec;///边权的类型
static const int ME=;///边的个数
static const int MV=;///点的个数
struct E {
int v,next;
typec w;
} e[ME];
int n,le,head[MV],inque[MV];
typec dist[MV];
bool used[MV];
queue<int> q;
public:
void init(int tn) { ///传入点的个数
n=tn;
le=;
mt(head,-);
}
void add(int u,int v,typec w) {
e[le].v=v;
e[le].w=w;
e[le].next=head[u];
head[u]=le++;
}
bool solve(int s) { ///传入起点,下标0开始,存在负环返回false
for(int i=; i<=n; i++) {
dist[i]=inf;
used[i]=true;
inque[i]=;
}
used[s]=false;
dist[s]=;
inque[s]++;
while(!q.empty()) q.pop();
q.push(s);
while(!q.empty()) {
int u=q.front();
q.pop();
used[u]=true;
for(int i=head[u]; ~i; i=e[i].next) {
int v=e[i].v;
if(can[v]) continue;
if(dist[v]>dist[u]+e[i].w) {
dist[v]=dist[u]+e[i].w;
if(used[v]) {
used[v]=false;
q.push(v);
inque[v]++;
if(inque[v]>n) return false;
}
}
}
}
return true;
}
typec getdist(int id) {
return dist[id];
}
} g;
int main(){
int n,m,u,v,w;
while(~scanf("%d%d",&n,&m),n|m){
g.init(n);
while(m--){
scanf("%d%d%d",&u,&v,&w);
g.add(u,v,w);
g.add(v,u,w);
}
int ans=;
for(int i=;i<n;i++){
mt(can,);
can[i]=true;
g.solve();
ans=max(ans,g.getdist(n));
}
if(ans==inf){
puts("Inf");
continue;
}
printf("%d\n",ans);
}
return ;
}

http://acm.hdu.edu.cn/showproblem.php?pid=5135

第三题,bfs。题意:给n个棒子的长度,可以任意挑3个一组组成三角形,不一定要全用完,问最后三角形之和最大是多少。做法:用二进制表示是否用过某个棒子,然后bfs。

bfs,有vis剪了一些情况40ms,vis去掉和下面dfs一样了

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
double area_triangle(double a,double b,double c) {//计算三角形面积,输入三边长
double s=(a+b+c)/;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
double len[],ans;
bool vis[<<][<<];
int n;
struct Q{
int sta;
double area;
}now,pre;
queue<Q> q;
bool judge(double x,double y,double z){
return x+y>z&&x+z>y&&y+z>x;
}
void bfs(){
mt(vis,);
now.sta=;
now.area=;
while(!q.empty()) q.pop();
q.push(now);
while(!q.empty()){
pre=q.front();
q.pop();
ans=max(ans,pre.area);
for(int i=;i<n;i++){
if((pre.sta>>i)&) continue;
for(int j=i+;j<n;j++){
if((pre.sta>>j)&) continue;
for(int k=j+;k<n;k++){
if((pre.sta>>k)&) continue;
if(!judge(len[i],len[j],len[k])) continue;
now.sta=pre.sta|(<<i)|(<<j)|(<<k);
if(vis[pre.sta][now.sta]) continue;
vis[pre.sta][now.sta]=true;
now.area=pre.area+area_triangle(len[i],len[j],len[k]);
q.push(now);
}
}
}
}
}
int main(){
while(~scanf("%d",&n),n){
for(int i=;i<n;i++){
scanf("%lf",&len[i]);
}
ans=;
bfs();
printf("%.2f\n",ans);
}
return ;
}

dfs暴力所有情况171ms

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const int M=;
int a[M],n;
bool use[M];
double ans;
bool judge(int x,int y,int z){
return x+y>z;
}
double area_triangle(double a,double b,double c) {//计算三角形面积,输入三边长
double s=(a+b+c)/;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
void dfs(double sum){
ans=max(ans,sum);
for(int i=;i<n;i++){
if(use[i]) continue;
for(int j=i+;j<n;j++){
if(use[j]) continue;
for(int k=j+;k<n;k++){
if(use[k]) continue;
if(!judge(a[i],a[j],a[k])) continue;
use[i]=use[j]=use[k]=true;
dfs(sum+area_triangle(a[i],a[j],a[k]));
use[i]=use[j]=use[k]=false;
}
}
}
}
int main(){
while(~scanf("%d",&n),n){
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
mt(use,);
ans=;
dfs();
printf("%.2f\n",ans);
}
return ;
}

状态压缩dp,非常厉害15ms

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const int M=;
int a[M],n;
double dp[<<];
vector<int> v;
bool judge(int x,int y,int z){
return x+y>z;
}
double area_triangle(double a,double b,double c) {//计算三角形面积,输入三边长
double s=(a+b+c)/;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
int main(){
while(~scanf("%d",&n),n){
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
mt(dp,);
int big=<<n;
for(int i=;i<n;i++){
for(int j=i+;j<n;j++){
for(int k=j+;k<n;k++){
if(!judge(a[i],a[j],a[k])) continue;
int sta=(<<i)|(<<j)|(<<k);
dp[sta]=area_triangle(a[i],a[j],a[k]);
v.push_back(sta);
}
}
}
int lv=v.size();
for(int i=;i<big;i++){
for(int j=;j<lv;j++){
if(i&v[j]) continue;
int next=i|v[j];
dp[next]=max(dp[next],dp[i]+dp[v[j]]);
}
}
printf("%.2f\n",dp[big-]);
}
return ;
}

http://acm.hdu.edu.cn/showproblem.php?pid=5128

第四题,枚举。题意:给n个点,任意挑8个点构成两个不相交矩形,问能得到最大面积。做法:先处理出所有矩形,然后n^2枚举出两个矩形,如果一个矩形完全在另一个内,边不相交,那面积就是大的矩形的面积,如果相交了那是不合法的,否则就是两个矩形面积和,最后求个面积最大值。

 #include<cstdio>
#include<cstring>
#include<vector>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
struct point{
int x,y;
}p[];
struct G{
int sx,sy,bx,by;
}now;
vector<G> g;
bool inside(G a,G b){
return a.sx>b.sx&&a.sy>b.sy&&a.bx<b.bx&&a.by<b.by;
}
int area(G a){
return (a.bx-a.sx)*(a.by-a.sy);
}
bool in(int x,int y,G b){
return x>=b.sx&&y>=b.sy&&x<=b.bx&&y<=b.by;
}
bool judge(G a,G b){
return in(a.sx,a.sy,b)||in(a.sx,a.by,b)||in(a.bx,a.sy,b)||in(a.bx,a.by,b);
}
bool vis[][];
int main(){
int n;
while(~scanf("%d",&n),n){
mt(vis,);
for(int i=;i<n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
vis[p[i].x][p[i].y]=true;
}
g.clear();
for(int i=;i<n;i++){
for(int j=;j<n;j++){
if(p[i].x<p[j].x&&p[i].y<p[j].y){
if(!vis[p[i].x][p[j].y]) continue;
if(!vis[p[j].x][p[i].y]) continue;
now.sx=p[i].x;
now.sy=p[i].y;
now.bx=p[j].x;
now.by=p[j].y;
g.push_back(now);
}
}
}
int lg=g.size();
int ans=;
for(int i=;i<lg;i++){
for(int j=i+;j<lg;j++){
if(inside(g[i],g[j])||inside(g[j],g[i])){
ans=max(ans,max(area(g[i]),area(g[j])));
continue;
}
if(judge(g[i],g[j])||judge(g[j],g[i])) continue;
ans=max(ans,area(g[i])+area(g[j]));
}
}
if(!ans){
puts("imp");
continue;
}
printf("%d\n",ans);
}
return ;
}

A

题目:1 x y加入x,y  ; -1 x y删去 x,y  ; 0 a b 查询之前加入的x*a+y*b最大值

暴力n2能过,标程比暴力还慢。。

 #include<cstdio>
typedef long long LL;
const int M=5e4+;
struct G{
LL x,y;
bool flag;
}q[M];
int main(){
int n,a;
LL b,c;
while(~scanf("%d",&n),n){
int lq=;
while(n--){
scanf("%d%lld%lld",&a,&b,&c);
if(a==){
q[lq].x=b;
q[lq].y=c;
q[lq].flag=true;
lq++;
continue;
}
if(a==-){
for(int i=;i<lq;i++){
if(!q[i].flag) continue;
if(q[i].x==b&&q[i].y==c){
q[i].flag=false;
break;
}
}
continue;
}
LL ans=-4e18,tmp;
for(int i=;i<lq;i++){
if(!q[i].flag) continue;
tmp=q[i].x*b+q[i].y*c;
if(ans<tmp){
ans=tmp;
}
}
printf("%lld\n",ans);
}
}
return ;
}

end

2014ACM/ICPC亚洲区广州站 北大命题的更多相关文章

  1. HDU 5127.Dogs' Candies-STL(vector)神奇的题,set过不了 (2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大))

    周六周末组队训练赛. Dogs' Candies Time Limit: 30000/30000 MS (Java/Others)    Memory Limit: 512000/512000 K ( ...

  2. HDU 5135.Little Zu Chongzhi's Triangles-字符串 (2014ACM/ICPC亚洲区广州站-重现赛)

    Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 ...

  3. HDU 5131.Song Jiang's rank list (2014ACM/ICPC亚洲区广州站-重现赛)

    Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java ...

  4. 2014ACM/ICPC亚洲区北京站 上交命题

    A http://acm.hdu.edu.cn/showproblem.php?pid=5112 输入n个时刻和位置,问那两个时刻间速度最快. 解法:按照时间排序,然后依次求相邻两个之间的速度,速度= ...

  5. 2014ACM/ICPC亚洲区广州站 Song Jiang's rank list

    欢迎参加——每周六晚的BestCoder(有米!) Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Li ...

  6. 2014ACM/ICPC亚洲区广州站题解

    这一场各种计算几何,统统没有做. HDU 5129 Yong Zheng's Death HDU 5136 Yue Fei's Battle

  7. 2014ACM/ICPC亚洲区西安站 复旦命题

    http://codeforces.com/gym/100548 A 签到 问一个序列是不是yes,yes的序列满足每个数都是3的倍数. #include<cstdio> int main ...

  8. 2014ACM/ICPC亚洲区鞍山站 清华命题

    A http://acm.hdu.edu.cn/showproblem.php?pid=5070 先跳过. B http://acm.hdu.edu.cn/showproblem.php?pid=50 ...

  9. 2014ACM/ICPC亚洲区牡丹江站 浙大命题

    A  Average Score http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 a班有n个人,b班有m个人,bob在a ...

随机推荐

  1. 使用sqoop将mysql数据导入到hadoop

    hadoop的安装配置这里就不讲了. Sqoop的安装也很简单. 完成sqoop的安装后,可以这样测试是否可以连接到mysql(注意:mysql的jar包要放到 SQOOP_HOME/lib 下): ...

  2. Ubuntu安装wps for linux

    1.WPS For Linux 2013 还是只提供了32位版本,我用的是 64位 Ubuntu,如果您也是64位系统,还需要提前安装一些32位的库文件. sudo apt-get install i ...

  3. 关于delphi XE7中的动态数组和并行编程(第一部分)

    本文引自:http://www.danieleteti.it/category/embarcadero/delphi-xe7-embarcadero/ 并行编程库是delphi XE7中引进的最受期待 ...

  4. 图表控件MsChart使用demo

    chart 控件主要有 Titles 标题集合  Chart Area图形显示区域 Series图表集合 Legends图列的集合 (1)  常用事件: 1. Series1.Points.DataB ...

  5. MTK机子修复分区信息

    这是前一个星期的事了,最近一直懒得写博客~ 此事是由于我误刷了内核,然后导致分区信息出错... 内置存储挂载不上,也找不到内置存储的分区! 如果不是star的帮助.估计俺的爪机就要返厂了!! 接下来说 ...

  6. linux kernel 0.11 setup

    setup作用 ①读取参数放在0x90000处. ②将原本在0x10000处的system模块移至0x00000处 ③加载中断描述符表,全局描述符表,进入32位保护模式. 概念 关于实模式和保护模式区 ...

  7. mysql索引合并:一条sql可以使用多个索引

    前言 mysql的索引合并并不是什么新特性.早在mysql5.0版本就已经实现.之所以还写这篇博文,是因为好多人还一直保留着一条sql语句只能使用一个索引的错误观念.本文会通过一些示例来说明如何使用索 ...

  8. Postgres Basic Commands for Beginners

    Just sharing what I have learned about postgres recently. Here is a part of basic commands you may n ...

  9. Redbean:入门(三) - Exec 以及 Query 以及 ConvertToBeans

    <?php //引入rb入口文件 include_once 'rb.php'; //定义dsn以及相关的数据 $dsn = 'mysql:host=localhost;dbname=hwibs_ ...

  10. JavaScript 编码风格指南

    A.1  缩进 // 4个空格的层级缩进 if (true) { doSomething(); } A.2  行的长度 // 每行限于80个字符,超出则在运算符后换行,缩进2个层级(8个空格) doS ...