传送门: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 5984 | Save 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;
}