A - Repeating Characters
简单题,把字符串里的每个字符连续输出k个即可
代码:
#include <iostream>//A Hdu 4236 开始
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define lson l,mid,num<<1
#define rson mid+1,r,num<<1|1
using namespace std;
const int M=100005;
int main()
{
int t,a,n;
char s[1001];
scanf("%d",&t);
while(t--)
{
memset(s,0,sizeof(s));
scanf("%d%d%s",&a,&n,s);
printf("%d ",a);
int len=strlen(s);
for(int i=0;i<len;i++)
{
for(int j=1;j<=n;j++)
{
printf("%c",s[i]);
}
}
printf("\n");
}
return 0;
}
B - The Rascal Triangle
题意:R(n, m) = 0 for n < 0 OR m < 0 OR m > n
R(n + 1, m + 1) = (R(n, m)*R(n, m + 1) + 1)/R(n - 1, m)
R(n, 0) = R(n, n) = 1
给出这么个公式,求R(n,m)
刚开始受题中图的影响,怎么也推不出来,后面施神提示了一下,按原数组性质画出这个图,可以发现有这样的规律
1
1 1
1 2 1
1 3 3 1
1 4 5 4 1
1 5 7 7 5 1
1 6 9 10 9 6 1
可以发现,第二列和倒数第二列都是成等差数列,且公差恰好为m,所以问题就转化成了求项数问题。。
仔细观察,发现问题恰好求第n-m项,则 s=1+m*(n-m)即为结果
代码:
#include <iostream>//B
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define lson l,mid,num<<1
#define rson mid+1,r,num<<1|1
using namespace std;
const int M=10005;
int main()
{
int t,a,n,m;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&a,&n,&m);
printf("%d %I64d\n",a,(long long)m*(n-m)+1);
}
return 0;
}
D - Decoding EDSAC Data
题意:按题目要求把输入的数全部转换成二进制表示,然后求对应的十进制小数
这题题目很容易理解,但是就是转换的时候有点麻烦,组队赛过程中确实学到很多东西,那个尾部去0的方法是组队赛中学会的
代码:
#include <iostream>//H
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define lson l,mid,num<<1
#define rson mid+1,r,num<<1|1
#define LL long long
using namespace std;
const int M=50005;
char a[]= {"PQWERTYUIOJ#SZK*?F@D!HNM&LXGABCV"};
map<char,string>tt;
string rev(int k,int num)
{
string s="";
int kk=0;
while(k!=0)
{
int g=k%2;
s+=g+'0';
k/=2;
kk++;
}
for(int i=1; i<=num-kk; i++)
s+='0';
reverse(s.begin(), s.end());
return s;
}
void ff()
{
for(int i=0; i<=31; i++)
{
string aa=rev(i,5);
tt[a[i]]=aa;
//cout<<tt[a[i]]<<endl;
}
}
int main()
{
ff();
int t,a,n;
char x,y;
cin>>t;
while(t--)
{
string s="";
cin>>a;
cin>>x>>n>>y;
if(x=='?' && n==0 && y=='F')
{
printf("%d -1.0\n",a);
continue;
}
s+=tt[x];
s+=rev(n,11);
if(y=='F')s+='0';
else s+='1';
//cout<<"s: "<<s<<endl;
printf("%d ",a);
if(s[0]=='1')
{
printf("-");
int h;
for(h=16; h>=1; h--)
{
if(s[h]=='1')break;
}
for(int j=h-1; j>=1; j--)
{
if(s[j]=='0')s[j]='1';
else
s[j]='0';
}
}
double sum=0.0;
for(int i=16; i>=1; i--)//我想到跟求整数的二进制一样,就试试,没错!
{
sum=sum*0.5+s[i]-'0';
}
sum/=2;
char ss[22];
sprintf(ss,"%.16f",sum);
int len=strlen(ss),i;
//cout<<"ss: "<<ss<<endl;
for(i=len-1; i>=0; i--)
{
if(ss[i]!='0')
{
if(ss[i]=='.')
{
ss[i+2]='\0';
break;
}
else
{
ss[i+1]='\0';
break;
}
}
}
cout<<ss<<endl;
}
return 0;
}
G - Rancher's Gift
题意:题意很简单,就是求四个三角形的面积和中间四边形的面积以及周长,注意单位的转换
其实蛮简单的,就是繁琐,把两直线的交点求出来,我可是弄了好久
代码:
#include <iostream>//G
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define lson l,mid,num<<1
#define rson mid+1,r,num<<1|1
#define LL long long
using namespace std;
double gety(double xa,double ya,double x1,double y1,double xd,double yd,double x2,double y2)
{
double s1=(yd-y1)*(ya-y2)*xd+(ya-y2)*(x1-xd)*yd+(y1-yd)*(ya-y2)*x2+(x2-xa)*(y1-yd)*y2;
double s2=(xa-x2)*(yd-y1)+(x1-xd)*(ya-y2);
return s1/s2;
}
double getx(double xa,double ya,double x2,double y2,double y)
{
double s=xa+(((y-ya)*(x2-xa))/(y2-ya));
return s;
}
double dis(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double getarea(double a,double b,double c)
{
double s=(a+b+c)/2;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
int main()
{
int t,a;
double x1,x2,x3,x4,y1,y2,y3,y4,s1,s2,s3,cc1,cc2,cc3,cc4;
double xa,xb,xc,xd,ya,yb,yc,yd,sa,sb,sc,sd,se,sf;
double xx1,xx2,xx3,xx4,yy1,yy2,yy3,yy4,c1,c2,c3,c4;
scanf("%d",&t);
while(t--)
{
xa=ya=yb=0;
scanf("%d",&a);
printf("%d",a);
scanf("%lf %lf %lf %lf %lf",&xb,&xc,&yc,&xd,&yd);
x1=(xa+xb)/2;
y1=(ya+yb)/2;//ab
x2=(xb+xc)/2;
y2=(yb+yc)/2;//bc
x3=(xc+xd)/2;
y3=(yc+yd)/2;//cd
x4=(xd+xa)/2;
y4=(yd+ya)/2;//da
yy1=gety(xa,ya,x1,y1,xd,yd,x2,y2);//1
xx1=getx(xa,ya,x2,y2,yy1);
yy2=gety(xb,yb,x2,y2,xa,ya,x3,y3);//2
xx2=getx(xb,yb,x3,y3,yy2);
yy3=gety(xc,yc,x3,y3,xb,yb,x4,y4);//3
xx3=getx(xc,yc,x4,y4,yy3);
yy4=gety(xd,yd,x4,y4,xc,yc,x1,y1);//4
xx4=getx(xd,yd,x1,y1,yy4);
//printf("%.3lf %.3lf\n%.3lf %.3lf\n",xx1,yy1,xx2,yy2);
// printf("%.3lf %.3lf\n%.3lf %.3lf\n",xx3,yy3,xx4,yy4);
s1=dis(xa,ya,xb,yb);
s2=dis(xb,yb,xx2,yy2);
s3=dis(xa,ya,xx2,yy2);
sa=getarea(s1,s2,s3);
s1=dis(xc,yc,xx3,yy3);
s2=dis(xb,yb,xc,yc);
s3=dis(xb,yb,xx3,yy3);
sb=getarea(s1,s2,s3);
s1=dis(xc,yc,xx4,yy4);
s2=dis(xc,yc,xd,yd);
s3=dis(xd,yd,xx4,yy4);
sc=getarea(s1,s2,s3);
s1=dis(xd,yd,xa,ya);
s2=dis(xd,yd,xx1,yy1);
s3=dis(xa,ya,xx1,yy1);
sd=getarea(s1,s2,s3);
cc1=dis(xx1,yy1,xx2,yy2);
cc2=dis(xx2,yy2,xx3,yy3);
cc3=dis(xx3,yy3,xx4,yy4);
cc4=dis(xx4,yy4,xx1,yy1);
double cc5=dis(xx1,yy1,xx3,yy3);
sf=getarea(cc1,cc2,cc5)+getarea(cc3,cc4,cc5);
se=cc1+cc2+cc3+cc4;
printf(" %.3lf %.3lf %.3lf %.3lf %.3lf %.0lf\n",sa/160,sb/160,sc/160,sd/160,sf/160,ceil(se*16.5));
}
return 0;
}