HDU4716
简单题
#include<iostream>
#include<cstdio>
using namespace std;
char a[12][14];
void print()
{
for(int i=0;i<12;i++)
{
for(int j=0;j<14;j++)
{
cout<<a[i][j];
}
cout<<endl;
}
}
void init()
{
a[0][0]=a[0][13]=a[11][0]=a[11][13]='*';
for(int j=1;j<13;j++)
{
a[0][j]='-';
a[11][j]='-';
}
for(int i=1;i<11;i++)
{
a[i][0]=a[i][13]='|';
}
for(int i=1;i<11;i++)
{
for(int j=1;j<13;j++)
{
a[i][j]='.';
}
}
}
int main()
{
int n,t;
init();
cin>>t;
for(int i=1;i<=t;i++)
{
cin>>n;
printf("Case #%d:\n",i);
for(int i=11;i>=11-n/10;i--)
{
for(int j=1;j<13;j++)
{
a[i][j]='-';
}
}
print();
init();
}
return 0;
}
HDU4720
最小点集覆盖圆
可做模板
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=20;
const int INF=0xffffff;
struct pointset
{
double x, y;
};
const double precison=1.0e-8;
pointset maxcic, point[N];
double radius;
int curset[N], posset[3];
int set_cnt, pos_cnt;
inline double dis_2(pointset &from, pointset& to)
{
return ((from.x-to.x)*(from.x-to.x)+(from.y-to.y)*(from.y-to.y));
}
int in_cic(int pt)
{
if(sqrt(dis_2(maxcic, point[pt]))<radius+precison)
return 1;
return 0;
}
int cal_mincic()
{
if(pos_cnt==1 || pos_cnt==0)
return 0;
else if(pos_cnt==3)
{
double A1, B1, C1, A2, B2, C2;
int t0=posset[0], t1=posset[1], t2=posset[2];
A1=2*(point[t1].x-point[t0].x);
B1=2*(point[t1].y-point[t0].y);
C1=point[t1].x*point[t1].x-point[t0].x*point[t0].x+
point[t1].y*point[t1].y-point[t0].y*point[t0].y;
A2=2*(point[t2].x-point[t0].x);
B2=2*(point[t2].y-point[t0].y);
C2=point[t2].x*point[t2].x-point[t0].x*point[t0].x+
point[t2].y*point[t2].y-point[t0].y*point[t0].y;
maxcic.y=(C1*A2-C2*A1)/(A2*B1-A1*B2);
maxcic.x=(C1*B2-C2*B1)/(A1*B2-A2*B1);
radius=sqrt(dis_2(maxcic, point[t0]));
}
else if(pos_cnt==2)
{
maxcic.x=(point[posset[0]].x+point[posset[1]].x)/2;
maxcic.y=(point[posset[0]].y+point[posset[1]].y)/2;
radius=sqrt(dis_2(point[posset[0]], point[posset[1]]))/2;
}
return 1;
}
int mindisk()
{
if(set_cnt==0 || pos_cnt==3)
{
return cal_mincic();
}
int tt=curset[--set_cnt];
int res=mindisk();
set_cnt++;
if(!res || !in_cic(tt))
{
set_cnt--;
posset[pos_cnt++]=curset[set_cnt];
res=mindisk();
pos_cnt--;
curset[set_cnt++]=curset[0];
curset[0]=tt;
}
return res;
}
int main()
{
//freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
int tcas,tcase=0;
int n;
scanf("%d",&tcas);
while(tcas--)
{
tcase++;
printf("Case #%d: ",tcase);
n=3;
int i;
for(i=0; i<=n; i++)
scanf("%lf%lf", &point[i].x, &point[i].y);
set_cnt=n;
pos_cnt=0;
for(i=0 ; i<n ; i++)
curset[i]=i;
mindisk();
// printf("%.2lf %.2lf %.2lf\n", maxcic.x, maxcic.y, radius);
point[4].x=maxcic.x;
point[4].y=maxcic.y;
if(sqrt(dis_2(point[3],point[4]))<=radius+precison)
puts("Danger");
else
puts("Safe");
}
return 0;
}
HDU4722
树形DP
#include<cstdio>
#include<cstring>
using namespace std;
#define lint long long
#define N 20
int bit[N];
lint dp[N][11];
lint dfs(int i,int j,bool limit)
{
if(i<0)return j==0;
if(!limit&&dp[i][j]!=-1)return dp[i][j];
int end=limit?bit[i]:9;
lint ans=0;
for(int x=0; x<=end; ++x)
{
ans+=dfs(i-1,(j+x)%10,limit&&x==end);
}
if(!limit)
{
dp[i][j]=ans;
}
return ans;
}
lint solve(lint n)
{
if(n<0)return 0;
memset(dp,-1,sizeof(dp));
int len=-1;
lint x=n;
while(x)
{
bit[++len]=x%10;
x/=10;
}
return dfs(len,0,1);
}
int main()
{
int t,T=1;
lint n,m;
scanf("%d",&t);
while(t--)
{
scanf("%I64d%I64d",&n,&m);
--n;
printf("Case #%d: %I64d\n",T++,solve(m)-solve(n));
}
return 0;
}
HDU4726
高精度的思想
#include<cstdio>
#include<cstring>
using namespace std;
#define N 1000005
int a[11],b[11],c[11];
char sa[N],sb[N],s[N];
void init()
{
memset(c,0,sizeof(c));
for(int i=9; i>=0; --i)
{
for(int j=0; j<10; ++j)
{
while(a[j]>0&&b[(i-j+10)%10]>0)
{
--a[j],--b[(i-j+10)%10];
++c[i];
}
}
}
}
int get(int r=0)
{
int x=0,y=0,ans=-1;
for(int i=9; i>=r; --i)
{
if(a[i]<=0)continue;
for(int j=9; j>=r; --j)
{
if(b[j]>0)
{
if((i+j)%10>ans)
{
ans=(i+j)%10;
x=i,y=j;
}
}
}
}
--a[x];
--b[y];
return ans;
}
int main()
{
//freopen("G:\\in.txt","r",stdin);
int t,T=1,v;
scanf("%d",&t);
while(t--)
{
scanf("%s%s",sa,sb);
printf("Case #%d: ",T++);
if(sa[0]=='0'&&sb[0]=='0')
{
puts("0");
continue;
}
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
int asize=strlen(sa),bsize=strlen(sb);
for(int i=0; i<asize; ++i)++a[sa[i]-'0'];
for(int i=0; i<bsize; ++i)++b[sb[i]-'0'];
v=0;
if(asize<bsize)
{
int z=bsize-asize;
for(int i=9; i>=0; --i)
{
if(b[i]<=z)
{
z-=b[i];
while(b[i])s[v++]=i+'0',--b[i];
}
else
{
b[i]-=z;
while(z)s[v++]=i+'0',--z;
}
if(z==0)break;
}
init();
int k=9;
while(c[k]==0)--k;
for(int i=0; i<asize; ++i)
{
s[v++]=k+'0';
if((--c[k])==0)
{
while(c[k]==0)--k;
}
}
s[v]='\0';
}
else if(asize>bsize)
{
int z=asize-bsize;
for(int i=9; i>=0; --i)
{
if(a[i]<=z)
{
z-=a[i];
while(a[i])s[v++]=i+'0',--a[i];
}
else
{
a[i]-=z;
while(z)s[v++]=i+'0',--z;
}
if(z==0)break;
}
init();
int k=9;
while(c[k]==0)--k;
for(int i=0; i<bsize; ++i)
{
s[v++]=k+'0';
if((--c[k])==0)
{
while(c[k]==0)--k;
}
}
s[v]='\0';
}
else
{
s[v++]=get(1)+'0';
init();
int k=9;
while(c[k]==0)--k;
for(int i=1; i<asize; ++i)
{
s[v++]=k+'0';
if((--c[k])==0)
{
while(c[k]==0)--k;
}
}
s[v]='\0';
}
bool flag=0;
for(int i=0;i<v;++i)
{
if(flag)putchar(s[i]);
if(!flag&&s[i]!='0')
{
putchar(s[i]);
flag=1;
}
}
if(!flag)putchar(s[v-1]);
puts("");
}
return 0;
}
HDU4727
简单题
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100005
int a[N];
int main()
{
int t,n,T=1;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
bool flag=0;
int ans=1;
for(int i=0;i<n;++i)
{
scanf("%d",a+i);
if(flag)continue;
if(i>0&&a[i]-a[i-1]!=1)
{
ans=i+1;
flag=1;
}
}
printf("Case #%d: %d\n",T++,ans);
}
return 0;
}