群赛56(B,E,G,K)

传送门:http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=12255#overview

开场看A题,以为是简单的深搜...囧

K题LightOJ 1414,计算给定年份间的2月29个数即闰年数。根据计算闰年的公式可以推出。

R/4-R/100+R/400-(L/4-L/100+L/400)。再判断下首尾。

        if(strcmp(month2,"January")==0||(strcmp(month2,"February")==0)&&day2<29)
             r--;
        if(strcmp(month1,"January")==0||strcmp(month1,"February")==0)
             l--;
        r=r/4-r/100+r/400;
        l=l/4-l/100+l/400;
        leap=r-l;


开始还二分了下还是T了

G题大水,

E题UVALive 5987 水.求第几个3个质数乘积。但是错了13次。跪。暴力T_T

B题

UVALive 5984Save the Students!
几何.求在范围内的点的数目.呜呜呜...又错了一个上午.

求大牛指教!!!

/*
Problem ID:
meaning:
Analyzing:
*/
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>

using namespace std;
typedef struct even{int y1,y2,x;}even;

#define FOR(i,s,t) for(int i=(s); i<(t); i++)
#define LL long long
#define BUG puts("here!!!")
#define print(x) printf("%d\n",x)
#define STOP system("pause")
#define eps 1e-8
#define PI acos(-1.0)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define maxn 16666
LL gcd(LL a,LL b) {return a?gcd(b%a,a):b;}
double getsquare(int x1,int y1,int x2,int y2,int x3,int y3){
    return (double)(x1*y2-x1*y3+x2*y3+x3*y1-x3*y2-x2*y1)*0.5;
    //return (x1-x3)*(y2-y3)-(y1-y3)*(x2-x3);
}
bool iscirle(int x,int y,int x1,int y1,int r){
    if(((x1-x)*(x1-x)+(y1-y)*(y1-y))<=r*r) return true;
    else return false;
}
bool issqure(int x,int y,int x1,int y1,int l){
    if(x>=x1&&y>=y1&&x<=x1+l&&y<=y1+l) return true;
    else return false;
}
bool isT(int x,int y,int x1,int y1,int x2,int y2,int x3,int y3){
    double SABC=getsquare(x1,y1,x2,y2,x3,y3);
    double SPAB=getsquare(x,y,x2,y2,x3,y3);
    double SPAC=getsquare(x,y,x3,y3,x1,y1);
    double SPBC=getsquare(x,y,x2,y2,x1,y1);
    if(abs(abs(SABC)-abs(SPAB)-abs(SPBC)-abs(SPAC))<eps) return true;
    else return false;
}
int main(){
    int T,N,x1[55],y1[55],x2[55],y2[55],x3[55],y3[55],l[55],r[55];
    char op[55][5];
    cin>>T;
    while(T--){
        cin>>N;
        for(int i=1;i<=N;i++){
            scanf("%s",op[i]);
            if(op[i][0]=='T'){
                scanf("%d%d%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i],&x3[i],&y3[i]);
            }
            else if(op[i][0]=='S'){
                scanf("%d%d%d",&x1[i],&y1[i],&l[i]);
            }
            else {
                scanf("%d%d%d",&x1[i],&y1[i],&r[i]);
            }
        }
        int num=0;
        for(int i=1;i<=50;i++){
        for(int j=1;j<=50;j++){
        for(int k=1;k<=N;k++){
                if(op[k][0]=='S') if(issqure(i,j,x1[k],y1[k],l[k])){num++;break;}
                if(op[k][0]=='C') if(iscirle(i,j,x1[k],y1[k],r[k])){ num++;break;}
                if(op[k][0]=='T') if(isT(i,j,x1[k],y1[k],x2[k],y2[k],x3[k],y3[k])){num++;break;}
            }
        }
        }
        cout<<num<<endl;
    }
   return 0;
}


B题处理三角形时还是有点麻烦的,方法有根据面积判断的和根据向量判断的。

根据向量判断比如:

int cross(int x1, int y1, int x2, int y2, int x, int y) {
	int ax = x1 - x, ay = y1 - y, bx = x2 - x, by = y2 - y;
	return ax * by - ay * bx;
}

bool inTri(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) {
	return abs(cross(x1, y1, x2, y2, x3, y3)) == 
		abs(cross(x1, y1, x2, y2, x, y)) +
		abs(cross(x1, y1, x3, y3, x, y)) +
		abs(cross(x3, y3, x2, y2, x, y));
}

根据面积比较直观:



double getsquare(int x1,int y1,int x2,int y2,int x3,int y3){
    return (double)(x1*y2-x1*y3+x2*y3+x3*y1-x3*y2-x2*y1)*0.5;
    //return (x1-x3)*(y2-y3)-(y1-y3)*(x2-x3);
}

bool isT(int x,int y,int x1,int y1,int x2,int y2,int x3,int y3){
    double SABC=getsquare(x1,y1,x2,y2,x3,y3);
    double SPAB=getsquare(x,y,x2,y2,x3,y3);
    double SPAC=getsquare(x,y,x3,y3,x1,y1);
    double SPBC=getsquare(x,y,x2,y2,x1,y1);
    if(abs(abs(SABC)-abs(SPAB)-abs(SPBC)-abs(SPAC))<eps) return true;
    else return false;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值