暑假练习记录(二)2014广州赛区

一,Dogs' Candies

暴力,开long long ,莫名其妙的wa,莫名其妙的ac

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5+100;
const int inf=0x3f3f3f3f;
int a1[maxn],b1[maxn];
int main(){
	int n;
	while(cin>>n,n){
		memset(a1,0,sizeof a1);
		memset(b1,0,sizeof b1);
		int cnt=0;
		for(int i=0;i<n;i++){
			ll t,x,y;
			cin>>t>>x>>y;
			if(t==1){
				a1[cnt]=x;
				b1[cnt++]=y;
			}else if(t==-1){
				for(int j=0;j<cnt;j++){
					if(a1[j]==x&&b1[j]==y){
						a1[j]=0;b1[j]=0;break;
					}
				}
			}else {
				ll temp=-inf;
				for(int j=0;j<cnt;j++){
					ll c1=x*a1[j]+y*b1[j];
					if(c1>temp)temp=c1;
				}
				cout<<temp<<endl;
			}
		}
	}
	return 0;
}

二,The E-pang Palace

枚举可能组成的矩形,枚举矩形选择,不断最大,暴力,莽就是了,,,对了,提前对各店排好序,就莫名ac

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;
struct Node{
	int x,y;
}node[35];
struct rect{
	Node l,r;
	int area;
};
bool cmp(Node a,Node b){
	if(a.x!=b.x)return a.y<b.y;
	return a.x<b.x;
}
bool vis[300000];
vector<rect> a;
int main(){
	int n;
	while(~scanf("%d",&n),n){
		a.clear();
		memset(vis,0,sizeof vis);
		for(int i=0;i<n;i++){
			scanf("%d%d",&node[i].x,&node[i].y);
			vis[node[i].x*1000+node[i].y]=1;
		}
		sort(node,node+n,cmp);
		if(n<8){
			printf("imp\n");continue;
		}			
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n;k++){
					rect re;
					if(node[i].x==node[j].x&&node[i].y==node[k].y&&vis[node[j].y+1000*node[k].x]==1){
						Node l,r;
						l.x=min(node[i].x,node[k].x);l.y=min(node[i].y,node[j].y);
						r.x=max(node[i].x,node[k].x);r.y=max(node[i].y,node[j].y);
						re.l=l,re.r=r;
						re.area=(r.y-l.y)*(r.x-l.x);
						a.push_back(re);
					}else if(node[i].x==node[k].x&&node[i].y==node[j].y&&vis[node[k].y+1000*node[j].x]==1){
						Node l,r;
						l.x=min(node[i].x,node[j].x);l.y=min(node[i].y,node[k].y);
						r.x=max(node[i].x,node[j].x);r.y=max(node[i].y,node[k].y);
						re.l=l,re.r=r;
						re.area=(r.y-l.y)*(r.x-l.x);
						a.push_back(re);
					}
				}
			}
		}
		int len=a.size();
	//	for(int i=0;i<len;i++){
	//		printf("%d %d %d %d \n",a[i].l.x,a[i].l.y,a[i].r.x,a[i].r.y);
	//	}
		int maxs=0;
		for(int i=0;i<len;i++){
			for(int j=i+1;j<len;j++){
				int x1=a[i].l.x,x2=a[i].r.x;
				int y1=a[i].l.y,y2=a[i].r.y;
				int x3=a[j].l.x,x4=a[j].r.x;
				int y3=a[j].l.y,y4=a[j].r.y;
				if(x1==x3&&x2==x4&&y1==y3&&y2==y4)continue;
				if(x2<x3||x1>x4||y2<y3||x1>x4){				
					maxs=max(maxs,a[i].area+a[j].area);
				}else if(x1>x3&&x2<x4&&y1>y3&&y2<y4){
					maxs=max(maxs,a[j].area);
				}else if(x1<x3&&x2>x4&&y1<y3&&y2>y4){
					maxs=max(maxs,a[i].area);
				}
			}
		}
		if(maxs>0)printf("%d\n",maxs);
		else printf("imp\n");
	} 
	return 0;
} 

三,Yong Zheng's Death

今天wa的第一发,等待补题,,,,

四,Signal Interference

赛后补题,计算几何模板题,可惜,模板额木有,感谢大佬的题解和模板,,,(转载,转到大佬博客

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define eps 1e-8
using namespace std;
#define N 100017

struct Point{
    double x,y;
    Point(double x=0, double y=0):x(x),y(y) {}
    void input() { scanf("%lf%lf",&x,&y); }
};
typedef Point Vector;
struct Circle{
    Point c;
    double r;
    Circle(){}
    Circle(Point c,double r):c(c),r(r) {}
    Point point(double a) { return Point(c.x + cos(a)*r, c.y + sin(a)*r); }
    void input() { scanf("%lf%lf%lf",&c.x,&c.y,&r); }
};
int dcmp(double x) {
    if(x < -eps) return -1;
    if(x > eps) return 1;
    return 0;
}
template <class T> T sqr(T x) { return x * x;}
Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); }
Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); }
Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); }
bool operator < (const Point& a, const Point& b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
bool operator >= (const Point& a, const Point& b) { return a.x >= b.x && a.y >= b.y; }
bool operator <= (const Point& a, const Point& b) { return a.x <= b.x && a.y <= b.y; }
bool operator == (const Point& a, const Point& b) { return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0; }
double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; }
double Length(Vector A) { return sqrt(Dot(A, A)); }
double Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); }
double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }
Vector VectorUnit(Vector x){ return x / Length(x);}
Vector Normal(Vector x) { return Point(-x.y, x.x) / Length(x);}
double angle(Vector v) { return atan2(v.y, v.x); }
//-----------------计算几何必备-------------- 
bool OnSegment(Point P, Point A, Point B) {
    return dcmp(Cross(A-P,B-P)) == 0 && dcmp(Dot(A-P,B-P)) < 0;
}
double DistanceToSeg(Point P, Point A, Point B)
{
    if(A == B) return Length(P-A);
    Vector v1 = B-A, v2 = P-A, v3 = P-B;
    if(dcmp(Dot(v1, v2)) < 0) return Length(v2);
    if(dcmp(Dot(v1, v3)) > 0) return Length(v3);
    return fabs(Cross(v1, v2)) / Length(v1);
}
double DistanceToLine(Point P, Point A, Point B){
    Vector v1 = B-A, v2 = P-A;
    return fabs(Cross(v1,v2)) / Length(v1);
}
Point DisP(Point A, Point B){
    return Length(B-A);
}
bool SegmentIntersection(Point A,Point B,Point C,Point D) {
    return max(A.x,B.x) >= min(C.x,D.x) &&
           max(C.x,D.x) >= min(A.x,B.x) &&
           max(A.y,B.y) >= min(C.y,D.y) &&
           max(C.y,D.y) >= min(A.y,B.y) &&
           dcmp(Cross(C-A,B-A)*Cross(D-A,B-A)) <= 0 &&
           dcmp(Cross(A-C,D-C)*Cross(B-C,D-C)) <= 0;
}

Point Zero = Point(0,0);
double TriAngleCircleInsection(Circle C, Point A, Point B)
{
    Vector OA = A-C.c, OB = B-C.c;
    Vector BA = A-B, BC = C.c-B;
    Vector AB = B-A, AC = C.c-A;
    double DOA = Length(OA), DOB = Length(OB),DAB = Length(AB), r = C.r;
    if(dcmp(Cross(OA,OB)) == 0) return 0;
    if(dcmp(DOA-C.r) < 0 && dcmp(DOB-C.r) < 0) return Cross(OA,OB)*0.5;
    else if(DOB < r && DOA >= r) {
        double x = (Dot(BA,BC) + sqrt(r*r*DAB*DAB-Cross(BA,BC)*Cross(BA,BC)))/DAB;
        double TS = Cross(OA,OB)*0.5;
        return asin(TS*(1-x/DAB)*2/r/DOA)*r*r*0.5+TS*x/DAB;
    }
    else if(DOB >= r && DOA < r) {
        double y = (Dot(AB,AC)+sqrt(r*r*DAB*DAB-Cross(AB,AC)*Cross(AB,AC)))/DAB;
        double TS = Cross(OA,OB)*0.5;
        return asin(TS*(1-y/DAB)*2/r/DOB)*r*r*0.5+TS*y/DAB;
    }
    else if(fabs(Cross(OA,OB)) >= r*DAB || Dot(AB,AC) <= 0 || Dot(BA,BC) <= 0) {
        if(Dot(OA,OB) < 0) {
            if(Cross(OA,OB) < 0) return (-acos(-1.0)-asin(Cross(OA,OB)/DOA/DOB))*r*r*0.5;
            else                 return ( acos(-1.0)-asin(Cross(OA,OB)/DOA/DOB))*r*r*0.5;
        }
        else                     return asin(Cross(OA,OB)/DOA/DOB)*r*r*0.5;
    }
    else {
        double x = (Dot(BA,BC)+sqrt(r*r*DAB*DAB-Cross(BA,BC)*Cross(BA,BC)))/DAB;
        double y = (Dot(AB,AC)+sqrt(r*r*DAB*DAB-Cross(AB,AC)*Cross(AB,AC)))/DAB;
        double TS = Cross(OA,OB)*0.5;
        return (asin(TS*(1-x/DAB)*2/r/DOA)+asin(TS*(1-y/DAB)*2/r/DOB))*r*r*0.5 + TS*((x+y)/DAB-1);
    }
}
//data segment
Point p[507],A,B;
//data ends

int main()
{
    int n,i,j,cs = 1;
    double k;
    while(scanf("%d%lf",&n,&k)!=EOF)
    {
        for(i=1;i<=n;i++) p[i].input();
        A.input(), B.input(), p[n+1] = p[1];
        double D = (2.0*k*k*A.x-2.0*B.x)/(1.0-k*k);
        double E = (2.0*k*k*A.y-2.0*B.y)/(1.0-k*k);
        double F = (B.x*B.x+B.y*B.y-k*k*(A.x*A.x+A.y*A.y))/(1.0-k*k);
        Circle C = Circle(Point(-D*0.5,-E*0.5),sqrt(D*D+E*E-4.0*F)*0.5);
        double ans = 0.0;
        for(i=1;i<=n;i++)
            ans += TriAngleCircleInsection(C, p[i], p[i+1]);
        printf("Case %d: %.10f\n",cs++,fabs(ans));
    }
    return 0;
}

 五,Song Jiang's rank list

排序的水题,管什么前序后序,莽就是了,,,,

#include<cstdio>
#include<iostream>
#include<cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn=1e5+5;

struct node{
	string s;
	int x,id;
}out[300];
bool cmp(node a,node b){
	if(a.x!=b.x)return a.x>b.x;
	else return a.s<b.s;
}
int main(){  
	int n,m;
	while(cin>>n,n){	
		for(int i=0;i<n;i++){
			cin>>out[i].s>>out[i].x;
		}
		cin>>m;
		sort(out,out+n,cmp);
		for(int i=0;i<n;i++){
			cout<<out[i].s<<" "<<out[i].x<<endl;
		} 
		for(int i=0;i<m;i++){
			string ss;
			cin>>ss;
			int c1=0,c2=0;
			for(int i=0;i<n;i++){
				if(out[i].s==ss){
					c1=i;break;
				}
			}			
			for(int i=c1-1;i>=0;i--){
				if(out[i].x==out[c1].x)c2++;
			}
			printf("%d",c1+1-c2);
			if(c2!=0)printf(" %d\n",c2+1);
			else printf("\n");
		}
	}
	return 0;
} 

六,Train Scheduling 

等待补题,,,,,,,,

七,Squared Frequency

等待补题,,,,,,,,

八,Highway

等待补题,,,,,,,,

九,Little Zu Chongzhi's Triangles

贪心假算法,hdu的数据够渣,我就能过(滑稽/滑稽.jpg)

#include <bits/stdc++.h>
using namespace std;
int n,r[15];
bool vis[15];
int main(){
	while(cin>>n,n){
		for(int i=0;i<n;i++){
			cin>>r[i];vis[i]=0;
		}
		double ans=0;
		sort(r,r+n,greater<int>());
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n;k++){
					if(vis[i]||vis[j]||vis[k])continue;
					if(r[i]+r[j]>r[k]&&r[i]+r[k]>r[j]&&r[k]+r[j]>r[i]&&abs(r[i]-r[j])<r[k]&&abs(r[i]-r[k])<r[j]&&abs(r[j]-r[k])<r[i]){
						double p=(r[i]+r[j]+r[k])/2.0;
						double now=sqrt(p*(p-r[i])*(p-r[j])*(p-r[k]));
						ans+=now;
						vis[i]=vis[j]=vis[k]=1;
					}
				}
			}
		}
		printf("%.2lf\n",ans);
	}
	return 0;
}

十,Yue Fei's Battle 

等待补题,,,,,,,,

十一,How Many Maos Does the Guanxi Worth

枚举每个点,每个dijkstra跑一遍,哈哈哈哈哈,,,,

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxN = 100, inf = 0x3f3f3f3f;
bool visit[maxN];
int dis[maxN], map[maxN][maxN], n;
int dijkstra(int s) {
	//visit[i]为i是否被访问过,一开始都没访问过,所以都为false
	memset(visit, false, sizeof(visit));
	//dis[i]为源点s到i的最短路径,一开始都为inf
	memset(dis, inf, sizeof(dis));
	//起点到起点显然路径为0
	dis[s] = 0;
	visit[s] = true;
	int pos;
	for(int i=1;i<=n;i++)
	    dis[i]=map[1][i];
	for (int i = 1; i <= n; ++i) {
		pos = -1;
		int minn = inf;
		//需找最小的dis,pos赋值为-1是为了找到第一个
		for (int j = 1; j <= n; ++j)
			if (!visit[j] && minn > dis[j])minn=dis[j],pos = j;
		//如果是-1说明都访问过了
		//if (pos == -1)break;
		visit[pos]=true;
		//松弛
		for (int j = 1; j <= n; ++j)
			if (!visit[j])dis[j] = min(dis[j], dis[pos] + map[pos][j]);
	}
	//如果dis[t]=inf说明没有路到达t,否则最短路径为dis[t]
	return dis[n];
}
int te[100];
int main() {
	int  m, a, b, c;
	while(~scanf("%d%d", &n, &m)){
		if(n==0&&m==0)break;
		//map为邻接矩阵,先假设都没有路,即为inf
		memset(map, inf, sizeof(map));
		for(int i=1;i<=n;i++) {
			map[i][i]=0;
		}
		while (m--) {
			//输入a,b,c,代表a到b有一条代价为c的路
			scanf("%d%d%d", &a, &b, &c);
			map[a][b] =c; map[b][a] = c;
		}
		int ans=0;
		for(int i=2;i<n;i++){
			for(int j=1;j<=n;j++){
				te[j]=map[i][j];
				map[i][j]=inf,map[j][i]=inf;
			}
			int now=dijkstra(1);
			ans=max(now,ans);
			for(int j=1;j<=n;j++){
				map[i][j]=te[j],map[j][i]=te[j];
			}
			//printf("now:=%d\n",now);
		}
		if(ans>40000)printf("Inf\n");
		else printf("%d\n",ans);
	}
	return 0;
}

困死了,睡觉睡觉睡觉睡觉 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值