标签:des style blog http color io os java ar
A.GPA(HDU4802):
纯属进入状态用,给你一些字符串对应的权重,求加权平均,如果是N,P不计入统计
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1193 Accepted Submission(s): 743
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #include<cstring> using namespace std; int main() { int n,nn,num; double res,mid; char cc[5]; while(scanf("%d",&n)!=EOF){ res=0; num=0; for(int k=0;k<n;k++){ mid=0; scanf("%d%s",&nn,cc); if(cc[0]==‘P‘||cc[0]==‘N‘) continue; if(cc[0]==‘A‘){ if(cc[1]==‘\0‘) mid+=4.0; else if(cc[1]==‘-‘) mid+=3.7; } else if(cc[0]==‘B‘){ if(cc[1]==‘\0‘) mid+=3.0; else if(cc[1]==‘+‘) mid+=3.3; else if(cc[1]==‘-‘) mid+=2.7; } else if(cc[0]==‘C‘){ if(cc[1]==‘\0‘) mid+=2.0; else if(cc[1]==‘+‘) mid+=2.3; else if(cc[1]==‘-‘) mid+=1.7; } else if(cc[0]==‘D‘){ if(cc[1]==‘\0‘) mid+=1.3; else if(cc[1]==‘-‘) mid+=1.0; } num+=nn; res+=mid*nn; } if(num==0) printf("0.00\n"); else printf("%.2f\n",res/num); } return 0; }
B.Poor Warehouse Keeper(HDU4803)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1089 Accepted Submission(s): 312
题意:有个电子屏 上x,下y,上下各有按钮,上面的按钮保持分子分母比例使x+1,(也即x/y=(x+1)/(y+deltay)),下面的直接y+1,小数不显示但是不约去
赛时总结:打乱了smilewsw的节奏.....这题没做出来有三点
1.smile笔算算错了使我以为是下界没找对
2. 应该稍微比下界少一点就行了,这里的一点不是deltay为整数的时候就直接-1
3. double的运算应该放到一起去,不能先得到(y+deltay)换算成整数后再减去y,而是应该在得到整数前减去y,忽略了y可能是个小数这一点
解题思路:贪心,肯定应该介于x/(y+1),x/(y-1)之间,又因为比例越小,那么按上面的键y增的越多,所以不用管x/(y-1),尽量逼近但是又不超过x/(y+1)即可,所以设下限为x/(y+1-eps),
贪心证明在于这个比例只能被扩大不能缩小
#include<cstdio> using namespace std; int x,y; int main() { while(scanf("%d%d",&x,&y)==2){ if(x>y){puts("-1");continue;} if(x==1||x==y){printf("%d\n",y-1);continue;} double sub,dow; sub=x; dow=y+1-0.01; double ty=1;//用来放置过程中的y,过程中的x为i int ans=x-1;//肯定要增减x-1次,用于上方的键 for(int i=1;i<=x;i++){ int deltay=(int)((i*dow)/sub-ty);//按下方键的次数 ans+=deltay; ty+=deltay; ty=ty*(i+1)/i;//按了上方的键 } printf("%d\n",ans); } return 0; }
C. Campus Design(HDU4804):
Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 406 Accepted Submission(s): 201
题意:轮廓线DP
总结:不要无谓跟榜啊....I题缺少了关键性的,C和网络流却可以一发出的...微笑大神beautiful!明白轮廓线dp了
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #include<cstring> #define MOD 1000000007 using namespace std; long long dp[2][1<<11][21]; char a[200][50]; int main() { int n,m,c,d,i,j,used,k,cnt; while(scanf("%d %d %d %d",&n,&m,&c,&d)!=EOF) { memset(dp,0,sizeof(dp)); for(i=0;i<n;i++) scanf("%s",a[i]); dp[0][0][0]=1; cnt=0; for(i=0;i<n;i++) { for(j=0;j<m;j++) { memset(dp[1-cnt%2],0,sizeof(dp[1-cnt%2])); for(used=0;used<1<<m;used++) { for(k=0;k<=d;k++) { if((used>>j&1)||a[i][j]==‘0‘) dp[1-cnt%2][used&~(1<<j)][k]=(dp[1-cnt%2][used&~(1<<j)][k]+dp[cnt%2][used][k])%MOD; else { if(k<d) dp[1-cnt%2][used&~(1<<j)][k+1]=(dp[1-cnt%2][used&~(1<<j)][k+1]+dp[cnt%2][used][k])%MOD; if(j+1<m&&!(used>>(j+1)&1)&&a[i][j+1]==‘1‘) dp[1-cnt%2][used|1<<(j+1)][k]=(dp[1-cnt%2][used|1<<(j+1)][k]+dp[cnt%2][used][k])%MOD; if(i+1<n&&a[i+1][j]==‘1‘) dp[1-cnt%2][used|1<<j][k]=(dp[1-cnt%2][used|1<<j][k]+dp[cnt%2][used][k])%MOD; } } } cnt++; } } long long sum=0; for(i=c;i<=d;i++) { sum=(sum+dp[cnt%2][0][i])%MOD; } printf("%I64d\n",sum); } return 0; }
D. Shoot(HDU4805):
Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 315 Accepted Submission(s): 50
Special Judge
总结:这是一道计算几何,保持我队优良传统弃了它,何时等到可以进区域赛会重新看它的
#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <bitset> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <cassert> #include <cstdlib> #include <cstring> #include <iomanip> #include <sstream> #include <iostream> #include <algorithm> using namespace std; #define PB push_back #define MP make_pair #define AA first #define BB second #define OP begin() #define ED end() #define SZ size() #define SORT(x) sort(x.OP,x.ED) #define SQ(x) ((x)*(x)) #define SSP system("pause") #define cmin(x,y) x=min(x,y) #define cmax(x,y) x=max(x,y) typedef long long LL; typedef pair<int, int> PII; const double eps=1e-8; const double PI=acos(-1.); const LL MOD = 1000000007; int sign(double x) {return x<-eps?-1:x>eps;} struct spt { double x,y,z; spt(double _x=0,double _y=0,double _z=0) :x(_x),y(_y),z(_z) {} spt operator + (spt s) {return spt(x+s.x,y+s.y,z+s.z);} spt operator - (spt s) {return spt(x-s.x,y-s.y,z-s.z);} spt operator * (double s) {return spt(x*s,y*s,z*s);} spt operator / (double s) {return spt(x/s,y/s,z/s);} double len() const {return sqrt(SQ(x)+SQ(y)+SQ(z));} double operator * (spt s) {return x*s.x+y*s.y+z*s.z;} //点积dot spt operator ^ (spt s) { //叉积det spt ret; ret.x=y*s.z-z*s.y; ret.y=z*s.x-x*s.z; ret.z=x*s.y-y*s.x; return ret; } void output(char *s="") {printf("%s:%.6f %.6f %.6f\n",s,x,y,z);} void input() {scanf("%lf%lf%lf",&x,&y,&z);} } Orz(0,0,0); spt S,T,V,A,B,C; double disLP(spt p1,spt p2,spt q) { return fabs((p2-p1)*(q-p1)/(p2-p1).len()); } double disLL(spt p1,spt p2,spt q1,spt q2) { spt p=q1-p1,u=p2-p1,v=q2-q1; double d=(u*u)*(v*v)-SQ(u*v); if(sign(d)==0)return disLP(q1,q2,p1); double s=((p*u)*(v*v)-(p*v)*(u*v))/d; return disLP(q1,q2,p1+u*s); } int isFL(spt p,spt o,spt q1,spt q2,spt &is) { double a=o*(q2-p),b=o*(q1-p); double d=a-b; if(sign(d)==0)return 0; is=(q1*a-q2*b)/d; return 1; } int isFF(spt p1,spt o1,spt p2,spt o2,spt &ip,spt &io) { spt e=o1^o2; spt v=o1^e; double d=o2*v; if(sign(d)==0)return 0; ip=p1+v*(o2*(p2-p1))/d,io=e; return 1; } int inner(spt O,spt A,spt B,spt C) { double S=((B-A)^(C-A)).len(); double S1=((A-O)^(B-O)).len(); double S2=((A-O)^(C-O)).len(); double S3=((C-O)^(B-O)).len(); return sign(S-S1-S2-S3)==0; } int inner(double o,double a,double b) { return sign(max(a,b)-o)>=0&&sign(min(a,b)-o)<=0; } int inner(spt O,spt A,spt B) { return inner(O.x,A.x,B.x)&&inner(O.y,A.y,B.y)&&inner(O.z,A.z,B.z); } int main() { //freopen("","r",stdin); //freopen("","w",stdout); int i,j,k,u,v,w,p,q,r,n,m; while(~scanf("%d",&n)) { S.input(),T.input(); V.input(); double ans=0; spt U= (S-T) ^V; for(j=0; j<n; j++) { A.input(),B.input(),C.input(); spt D= (B-A) ^ (C-A); if(sign(D.len()) ==0) continue; if(sign(U.len())==0) { //TODO S->T Yu V PingXing spt is; int f=isFL(A,D,S,S+V,is); if(f) { ans+=inner(is,A,B,C); continue; } if(sign((S-A)*D))continue; spt iAB,iBC,iAC; int fAB=isFL(A,D^(A-B),S,S+V,iAB); int fBC=isFL(B,D^(B-C),S,S+V,iBC); int fAC=isFL(C,D^(C-A),S,S+V,iAC); fAB&=inner(iAB,A,B); fBC&=inner(iBC,B,C); fAC&=inner(iAC,A,C); ans+=fAB|fBC|fAC; continue; } if(sign(V*D)==0) { if(sign((S-A)*D)==0&&sign((T-A)*D)==0) { //TODO V//ABC && STABC on flat spt iA,iB,iC; int fA=isFL(S,(T-S)^D,A,A+V,iA); int fB=isFL(S,(T-S)^D,B,B+V,iB); int fC=isFL(S,(T-S)^D,C,C+V,iC); double len=(T-S).len(); double le=0,re=len; vector<double>L; if(fA)L.PB((iA-S)*(T-S)/len); if(fB)L.PB((iB-S)*(T-S)/len); if(fC)L.PB((iC-S)*(T-S)/len); sort(L.OP,L.ED); if(L.SZ<2)continue; double pe=L[0],qe=L[L.SZ-1]; cmax(pe,le); cmin(qe,re); if(qe>pe)ans+=(qe-pe)/len; } continue; } spt SP,TP,iAB,iBC,iAC; assert(isFL(A,D,S,S+V,SP)); assert(isFL(A,D,T,T+V,TP)); if(inner(SP,A,B,C)&&inner(TP,A,B,C)) {ans+=1; continue;} vector<spt>L; L.PB(SP),L.PB(TP); int fAB=isFL(A,D^(A-B),SP,TP,iAB); int fBC=isFL(B,D^(B-C),SP,TP,iBC); int fAC=isFL(C,D^(C-A),SP,TP,iAC); double len=(SP-TP).len(); if(fAB&&inner(iAB,SP,TP))for(i=0; i+1<L.SZ; i++) if(inner(iAB,L[i],L[i+1])) {L.insert(L.OP+i+1,iAB); break;} if(fBC&&inner(iBC,SP,TP))for(i=0; i+1<L.SZ; i++) if(inner(iBC,L[i],L[i+1])) {L.insert(L.OP+i+1,iBC); break;} if(fAC&&inner(iAC,SP,TP))for(i=0; i+1<L.SZ; i++) if(inner(iAC,L[i],L[i+1])) {L.insert(L.OP+i+1,iAC); break;} for(i=0; i+1<L.SZ; i++) { spt mid=(L[i]+L[i+1])/2; if(inner(mid,A,B,C)) ans+=(L[i+1]-L[i]).len()/len; } } printf("%.8f\n",ans); } return 0; }
E. Circular Lamps(HDU4806)
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/xuesu/p/3967704.html