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. IIS 7.5 配置Asp+Access的几点注意的地方

    环境:window2008 R2 + iis 7.51 把网站程序放在一个www文件夹里面,给这个文件夹添加everyone的用户,赋予全部读写权限,这样安全些.2 选中要配置的网站,点击页面中间“A ...

  2. php获取图片宽高等属性

    <?php function getImageInfo($image) {     $imageInfo = getimagesize($image);     if ($imageInfo ! ...

  3. apache2反向代理node.js应用

    在之前记录的随笔中,只是介绍了怎么在apache2中使用proxy模块,后来查到了一些资料,可以通过下面网址查看配置块的详细参数信息 http://man.ddvip.com/soft/apache2 ...

  4. .Net异步编程之Async与Await的使用

    参考教程:http://www.cnblogs.com/x-xk/archive/2013/06/05/3118005.html http://www.cnblogs.com/tdws/p/56790 ...

  5. 2016/09/21 java关键字static

    1.static方法     static方法一般称作静态方法,由于静态方法不依赖于任何对象就可以进行访问,因此对于静态方法来说,是没有this的,因为它不依附于任何对象,既然都没有对象,就谈不上th ...

  6. UCOS2_STM32F1移植详细过程(一)

    Ⅰ.概述 该文写针对初学µC/OS的朋友,基于以下平台来一步一步移植µC/OS嵌入式操作系统.UCOS移植相关平台: 系统平台:µC/OS-II  (最新V2.92版) 硬件平台:STM32F1    ...

  7. Python 有哪些优点?为何要学Python?

      1. 支持OOP编程 从根本上讲Python仍是一种面向对象的语言,支持多态.继承等高级概念,在Python里使用OOP十分容易 没有C++.Java那样复杂,但不必做Python下OOp高手,够 ...

  8. IE8中JSON.stringify方法对自动转换unicode字符的解决方案

    IE8内置了JSON对象,用以处理JSON数据.与标准方法的不同,IE8的JSON.stringify会把utf-8字符转码: var str = "我是程序员" var json ...

  9. hashCode()和toString()

    hashCode函数和toString函数也在Object类中,同样,所有的类都继承了这2个函数. hashCode函数用于生成哈希码,没有参数,返回值为整型 把u的值作为键存入map中,使用get方 ...

  10. 博客导出工具(C++实现,支持sina,csdn,自定义列表)

    操作系统:windowAll 编程工具:visual studio 2013 编程语言:VC++ 最近博文更新的较频繁,为了防止账号异常引起csdn博文丢失,所以花了点时间做了个小工具来导出博文,用做 ...