2014 Multi-University Training Contest 8

官方解题报告:http://blog.sina.com.cn/s/blog_a19ad7a10102uzj7.html

Area of Mushroom http://acm.hdu.edu.cn/showproblem.php?pid=4946

计算几何长知识,凸包中>是包括了凸包边上的点,>=是不包括边上的点,两种凸包的点数可能不同的。还有,传入凸包的点集不能有重复的点。

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const double eps=1e-;
const int M=;
struct point{
int x,y,id;
}p[M],res[M];
map<point,int> mp;
bool operator < (const point &l, const point &r) {
return l.y < r.y || (fabs(l.y- r.y)<eps && l.x < r.x);
}
class ConvexHull { //凸包
bool mult(point sp, point ep, point op) {// >包括凸包边上的点,>=不包括
return (sp.x - op.x) * (ep.y - op.y)> (ep.x - op.x) * (sp.y - op.y);
}
public:
int graham(int n,point p[],point res[]) {//多边形点个数和点数组,凸包存res
sort(p, p + n);
if (n == ) return ;
res[] = p[];
if (n == ) return ;
res[] = p[];
if (n == ) return ;
res[] = p[];
int top=;
for (int i = ; i < n; i++) {
while (top && mult(p[i], res[top], res[top-])) top--;
res[++top] = p[i];
}
int len = top;
res[++top] = p[n - ];
for (int i = n - ; i >= ; i--) {
while (top!=len && mult(p[i], res[top],res[top-])) top--;
res[++top] = p[i];
}
return top; // 返回凸包中点的个数
}
} gx;
int v[M];
bool ans[M];
int main(){
int n,cas=;
while(~scanf("%d",&n),n){
int big=;
for(int i=;i<n;i++){
scanf("%d%d%d",&p[i].x,&p[i].y,&v[i]);
p[i].id=i;
big=max(big,v[i]);
}
printf("Case #%d: ",cas++);
if(!big){
for(int i=;i<n;i++){
printf("");
}
puts("");
continue;
}
int lp=;
mp.clear();
for(int i=;i<n;i++){
if(v[i]==big){
if(!mp[p[i]]){
p[lp++]=p[i];
}
mp[p[i]]++;
}
}
int lr=gx.graham(lp,p,res);
mt(ans,);
for(int i=;i<lr;i++){
if(mp[res[i]]==){
ans[res[i].id]=true;
}
}
for(int i=;i<n;i++){
printf("%d",ans[i]);
}
puts("");
}
return ;
}

Monster http://acm.hdu.edu.cn/showproblem.php?pid=4950

 #include<cstdio>
typedef __int64 LL;
void yes(){
puts("YES");
}
void no(){
puts("NO");
}
int main(){
LL h,a,b,k;
int cas=;
while(~scanf("%I64d%I64d%I64d%I64d",&h,&a,&b,&k),h|a|b|k){
printf("Case #%d: ",cas++);
if(a>=h){
yes();
continue;
}
if(a<=b){
no();
continue;
}
if(k*a-(k-)*b>=h){
yes();
continue;
}
if(k*a-(k+)*b>){
yes();
continue;
}
no();
}
return ;
}

Number Transformation http://acm.hdu.edu.cn/showproblem.php?pid=4952

 #include<cstdio>
typedef __int64 LL;
int main() {
LL x,s;
int cas=;
while(~scanf("%I64d%I64d",&x,&s),x|s){
for(int i=;i<s;i++){
if(x<i+) break;
x=x-x/(i+);
}
printf("Case #%d: %I64d\n",cas++,x*s);
}
}

end

上一篇:HDU 1432 Lining Up (POJ 1118)


下一篇:java 正则提取字符串中的电话号码