2014ACM/ICPC亚洲区广州站 北大命题
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亚洲区广州站 北大命题的更多相关文章
- HDU 5127.Dogs' Candies-STL(vector)神奇的题,set过不了 (2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大))
周六周末组队训练赛. Dogs' Candies Time Limit: 30000/30000 MS (Java/Others) Memory Limit: 512000/512000 K ( ...
- 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 ...
- 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 ...
- 2014ACM/ICPC亚洲区北京站 上交命题
A http://acm.hdu.edu.cn/showproblem.php?pid=5112 输入n个时刻和位置,问那两个时刻间速度最快. 解法:按照时间排序,然后依次求相邻两个之间的速度,速度= ...
- 2014ACM/ICPC亚洲区广州站 Song Jiang's rank list
欢迎参加——每周六晚的BestCoder(有米!) Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- 2014ACM/ICPC亚洲区广州站题解
这一场各种计算几何,统统没有做. HDU 5129 Yong Zheng's Death HDU 5136 Yue Fei's Battle
- 2014ACM/ICPC亚洲区西安站 复旦命题
http://codeforces.com/gym/100548 A 签到 问一个序列是不是yes,yes的序列满足每个数都是3的倍数. #include<cstdio> int main ...
- 2014ACM/ICPC亚洲区鞍山站 清华命题
A http://acm.hdu.edu.cn/showproblem.php?pid=5070 先跳过. B http://acm.hdu.edu.cn/showproblem.php?pid=50 ...
- 2014ACM/ICPC亚洲区牡丹江站 浙大命题
A Average Score http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 a班有n个人,b班有m个人,bob在a ...
随机推荐
- jQuery身份证验证插件
jQuery身份证验证插件 /*! * jQuery isIDCard Plugin v1.0.0 * http://www.cnblogs.com/cssfirefly/p/5629561.html ...
- Creating an API-Centric Web Application[转]
Creating an API-Centric Web Application 转自 http://hub.tutsplus.com/tutorials/creating-an-api-centric ...
- C# 乘法口诀表的实现方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 乘法运算 ...
- [笔记]--Sublime Text 2使用技巧
Sublime个人喜好设置: 在打开个人设置页面Preferences >> Settings - User,加入以下内容: { , //TAB键,4个空格 "translate ...
- 插值和空间分析(二)_变异函数分析(R语言)
方法1.散点图 hscat(log(zinc)~, meuse, (:)*) 方法2.变异函数云图 library(gstat) cld <- variogram(log(zinc) ~ , m ...
- 菜鸟学习Hibernate——简单的增、删、改、查操作
上篇博客利用Hibernate搭建起一个简单的例子,把数据库的映射显示了出来在上一篇的博客基础上这篇博客讲述如何利用Hinbernate框架实现简单的数据库操作. 1.加入junit.jar 2.新建 ...
- Debug.print的用法
使用Debug.print可以用来更好的调试VBA程序 通过ALT+F11代开VBA编程窗口) 插入模块,接着在窗口中输入以下代码,按F5执行 Sub Excute() Debug.Print * + ...
- 详解iOS多线程 (转载)
iPhone 中的线程应用并不是无节制的,官方给出的资料显示iPhone OS下的主线程的堆栈大小是1M,第二个线程开始都是512KB.并且该值不能通过编译器开关或线程API函数来更改. 只有主线程有 ...
- jquery方法回到顶部代码
<style> /*默认样式,主要是position:fixed实现屏幕绝对定位*/ #gotoTop{display:none;position:fixed;top:75%;left:5 ...
- SVN基于一个branch创建新branch
在本地现有Branch(Checkout出来的目录)上,右键SVN,选择Branch/Tags,选择目录.比如https://sadcsc01.pmmr.com/web/Jaguar/branches ...