2011 大连网络赛 The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest 解题报告
昨天我们出了四个题,郁闷的我要死,好吧,结果就这样了,不在抱怨,下一场加油吧,祝愿下面的每一场都可以出现,阿门!
昨天我的发挥还算正常。
题目传送门:http://acm.hdu.edu.cn/search.php?field=problem&key=The%2036th%20ACM/ICPC%20Asia%20Regional%20Dalian%20Site%20——%20Online%20Contest&source=1&searchmode=source
这个题在赛场上我们没做出来,后来借来一个代码,一看傻眼了,好吧,这个题是动态规划,应该是我的强项的,但是,没出,主要的是这个题 我们都没读好题意,我大意了,
代码是别人的,就不贴了,思路就是:由于每一次都要求上面的长宽大于或者大于等于下面的长宽,这样的话,就可以排序了,昨天就这个没想明白,排完序之后就可以动态规划了,
B:
Find the maximum
这个题不是我的范围,我不懂
下面贴代码:
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define N 500010
int ll,n,m;
int data[N];
bool get(int len)
{
int now = 0;
int steps = 0;
for(int j = 1;steps <= n && j <= m;j++)
{
while(steps+1 <= n && data[steps+1]-data[now] <= len) steps++;
now = steps;
}
return now == n;
}
int main()
{
while(scanf("%d%d%d",&ll,&n,&m) != EOF)
{
data[0] = 0;
for(int i = 1;i <= n;i++)
scanf("%d",&data[i]);
sort(data,data+n+1);
data[++n] = ll;
int l = 1;int r = ll;
while(r > l)
{
int mid = (l + r) >> 1;
bool t = get(mid);
if(t)
r = mid;
else l = mid + 1;
}
printf("%d\n",l);
}
return 0;
}
F:
The kth great number
这个题用stl的优先队列就能过,当时想得比较多,结果用了比较长得时间,还好吧,这个题我们还是出了,其他的就不说了,这个我还是贴一下队友的代码吧
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <map>
using namespace std;
const int inf=1<<30;
int main()
{
int n,k,i;
while (scanf("%d%d",&n,&k)!=EOF)
{
bool mark=true;
int cnt=0;
int temp=cnt;
priority_queue<int,vector<int>,greater<int> > pq;
char code[2];
int a;
for(i=1;i<=k;i++){
scanf("%s %d",code,&a);
pq.push(a);
}
for(i=k+1;i<=n;i++){
scanf("%s",code);
if(code[0]=='I'){
scanf("%d",&a);
pq.push(a);
pq.pop();
}else{
printf("%d\n",pq.top());
}
}
}
return 0;
}
G:Dave 这个题当时我是出丑了,代码太繁杂,也是比较烂得代码
贴一下吧,以后教训:
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define N 1010
struct note
{
int x,y;
}po[N];
int x[N];
int ty[N];
int n,rr,maxx;
int cmp(const void *a,const void *b)
{
if((*(note*)a).x==(*(note*)b).x)
return (*(note*)a).y-(*(note*)b).y;
return (*(note*)a).x-(*(note*)b).x;
}
int get(int nn)
{
int ma = 0;
sort(ty,ty+nn);
int now = 0;
for(int i = 0;i < nn;i++)
{
while(ty[i] - ty[now] > rr) now++;
ma = max(ma,i - now + 1);
}
return ma;
}
int findL(int xx)
{
int l = 0;int r = n-1;
while(r > l)
{
int mid = (r + l) >> 1;
if(po[mid].x >= xx)
r = mid;
else l = mid+1;
}
return l;
}
int findR(int xx)
{
int l = 0;int r = n-1;
while(r > l)
{
int mid = (r + l + 1) >> 1;
if(po[mid].x > xx)
r = mid - 1;
else l = mid;
}
return r;
}
int main()
{
while(scanf("%d%d",&n,&rr) != EOF)
{
for(int i = 0;i < n;i++)
{
scanf("%d%d",&po[i].x,&po[i].y);
x[i] = po[i].x;
}
qsort (po,n,sizeof(note),cmp);
sort(x,x + n);
//sort x;
int j = 0;
for(int i=0;i<n;i++){
//cout << x[i] << "\n";
if(x[i] == x[j]) continue;
x[++j]=x[i];
}
maxx = 0;
//cout << j << "sdf";
for(int i = 0;i <= j;i++)
{
int lx = x[i];
int rx = x[i] + rr;
if(rx > x[j]) break;
int a = findL(lx);
int b = findR(rx);
//cout << b << " dfsaf";
for(int kk = a;kk <= b;kk++)
{
ty[kk - a] = po[kk].y;
}
maxx = max(maxx,get(b-a+1));
}
printf("%d\n",maxx);
}
return 0;
}
下面贴一个比较不错的:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
#define N 1010
struct Point
{
int x,y;
}P[N];
int Y[N],J;
int n,r;
bool cmp(Point a,Point b)
{
return a.x<a.x;
}
void getY(int x1,int x2)
{
int i;
J=0;
for(i=0;i<n;i++)
{
if(P[i].x>=x1&&P[i].x<=x2)
Y[J++]=P[i].y;
}
sort(Y,Y+J);
}
int how()
{
int ans=0;
int ans1=0;
int i,j,k;
int low=0;
for(i=0;i<J;i++)
{
while(Y[i]-Y[low]>r)low++;
ans=i+1-low;
if(ans1<ans)ans1=ans;
}
return ans1;
}
int main()
{
int i,j,k,ans,ans1;
while(scanf("%d%d",&n,&r)!=EOF)
{
ans1=ans=0;
for(i=0;i<n;i++)
{
scanf("%d%d",&P[i].x,&P[i].y);
}
sort(P,P+n,cmp);
int tt = -1;
for(i=0;i<n;i++)
{
if(P[i].x == tt) continue;
tt = P[i].x;
getY(P[i].x,P[i].x+r);
ans1=how();
if(ans<ans1)ans=ans1;
}
printf("%d\n",ans);
}
return 0;
}
版权声明:本文为wukonwukon原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。