杭电oj2050-2058————C语言

news/2024/10/19 5:28:12/

2050.折线分割平面

http://acm.hdu.edu.cn/showproblem.php?pid=2050
直线:第n条与之前的有 n-1 个交点,(n-1)+1 个平面;
折线:第n条最多与之前的有2∗2(n−1)交点(一折两直), 2∗2(n−1)+1个平面,
递推f(n)=f(n−1)+4n−3

第一种:

#include <stdio.h>
int cal(int n)
{return n==1?2:(cal(n-1)+4*(n-1)+1);
}int main()
{int c,n;scanf("%d",&c);while(c--){scanf("%d",&n);printf("%d\n",cal(n));}return 0;
}

第二种:

#include <stdio.h>
int main()
{int c,n;__int64 f[10001]={0,2,7};for(int i=3;i<=10000;i++){f[i]=f[i-1]+4*i-3;}scanf("%d",&c);while(c--){scanf("%d",&n);printf("%I64d\n",f[n]);}return 0;
}

2051.Bitset
和2031.进制转换差不多
http://acm.hdu.edu.cn/showproblem.php?pid=2051

#include<stdio.h>
int main()
{int n,i, arr[500], t = 0;while (~scanf("%d", &n) ){for ( i = 0; n!=0; i++){arr[i] = n % 2;n = n / 2;    }//i++是先执行再自增,多1for (int j = i-1; j >= 0; j--)printf("%d", arr[j]);printf("\n");}return 0;
}

2052.Picture
和2032.杨辉三角差不多,但是不要用数组做,数组会覆盖


#include <stdio.h>
int main()
{int n,m,i;while(~scanf("%d%d",&n,&m)){printf("+");for( i=0;i<n;i++)printf("-");printf("+\n");for( i=0;i<m;i++){printf("|");for(int j=0;j<n;j++)printf(" ");printf("|\n");}printf("+");for( i=0;i<n;i++)printf("-");printf("+\n");printf("\n");}return 0;
}

2053Switch Game
http://acm.hdu.edu.cn/showproblem.php?pid=2055

  1. 1 1 1 1 1 1 1 1 1 1 1 1 1
  2. 1 0 1 0 1 0 1 0 1 0 1 0 1
  3. 1 0 0 0 1 1 1 0 0 0 1 1 1
  4. 1 0 0 1 1 1 1 1 0 0 1 0 1
  5. 1 0 0 1 0 1 1 1 0 1 1 0 1
  6. 1 0 0 1 0 0 1 1 0 1 1 1 1
  7. 1 0 0 1 0 0 0 1 0 1 1 1 1
  8. 1 0 0 1 0 0 0 0 0 1 1 1 1
  9. 1 0 0 1 0 0 0 0 1 1 1 1 1
  10. 1 0 0 1 0 0 0 0 1 0 1 1 1

就是除了 n*n 是 1 ,其余的都是 0

#include<stdio.h>
#include<math.h>
int main()
{int n,k;while(~scanf("%d",&n)){k=sqrt(n);if(k*k==n) printf("1\n");else printf("0\n");}return 0;
}

2054

2055.An easy problem

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2055

本题要是有人设52个变量的话就有点沙雕
我是利用ascii码来算的
大写A是65 Z是90
A若要为1,只能65-64

小写a是97 z是122
a先乘-1再加96就能变为-1

#include <stdio.h>
int main()
{char i;int a,n;scanf("%d",&n);while(n--){scanf("%s %d",&i,&a);//输入int j=i;//转换为整数型int k=0;if(i>='A'&&i<='Z')//输入为大写时k=j-64;else //输入为小写时k=(-1)*j+96;printf("%d\n",k+a);}
return 0;
}

2056.Rectangles
http://acm.hdu.edu.cn/showproblem.php?pid=2056
翻译了c语言版本
http://blog.sina.com.cn/s/blog_ac5ed4f30101dr2z.html

#include <stdio.h>
int main()
{double x1,y1,x2,y2,x3,y3,x4,y4,a,b,c,d,t;while(~scanf("%lf%lf%lf%lf %lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)){if(x1>x2) {t=x1;x1=x2;x2=t;}if(x3>x4) {t=x3;x3=x4;x4=t;}if(y1>y2) {t=y1;y1=y2;y2=t;}if(y3>y4){t=y3;y3=y4;y4=t;}if(y2<y3||x2<x3||y1>y4||x1>x4)//最大的比你最小的还小,没的玩printf("0.00\n");else{if(x1<=x3)//双方最小的比较a=x3;elsea=x1;if(x2<=x4)//最大的比较b=x2;elseb=x4;if(y1<=y3)//最小的比较c=y3;elsec=y1;if(y2<=y4)//最大的比较d=y2;elsed=y4;printf("%.2lf\n",(b-a)*(d-c));//长×宽,有些解法是用fabs绝对值}}return 0;
}

2057.A + B Again
http://acm.hdu.edu.cn/showproblem.php?pid=2057
首先考虑范围大,其次对于负数需要注意
大写的X对应大写字母,小写x对应小写字母
16进制是%x ,大数就%I64x
8进制是%o
10进制是%d
不管是8进制还是16进制都是一样的方法

#include<stdio.h>
int main()
{__int64 a,b,c;while(scanf("%I64X %I64X",&a,&b)!=EOF){c=a+b;if(c>=0) {printf("%I64X\n",c);}else {printf("-%I64X\n",-c);}//正常是无法输出负数的}	return 0;
}	

2058.The sum problem
http://acm.hdu.edu.cn/showproblem.php?pid=2058
首项为a,如果个数为t,则尾项为a+t-1
等差数列公式:
(a+(a+t-1))*t/2=m
化简求得a=m/t+(t-1)/2,
先求t

#include <stdio.h>
int main()
{double n,m,a,t,i;while(~scanf("%lf%lf",&n,&m)){if(n==0&&m==0) break;for(i=0;i<m;i++){a=m/i-(i-1)/2;if(a<1) break;}//目的是为了限制a和t的范围,首项a有可能是负的for(t=i-1;t>=0;t--)//t是为了求长度,t=i-1是因为i++的性质{a=m/t-(t-1)/2;if(a-(int)a==0.0) //还是为了限制aprintf("[%d,%d]\n",(int)a,(int)a+(int)t-1);}printf("\n");}return 0;
}

http://www.ppmy.cn/news/622423.html

相关文章

杭电OJ2050

杭电OJ2050 #include <stdio.h> int main(){int c,n;while(scanf("%d",&c)!EOF){while(c--){scanf("%d",&n);int sum2*n*n-n1; //直接代公式printf("%d\n",sum);}}return 0; }

王小二切饼 C 2050

王小二切饼 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 王小二自夸刀工不错&#xff0c;有人放一张大的煎饼在砧板上&#xff0c;问他&#xff1a;“饼不许离开砧板&#xff0c;切n(1<n<100)刀最多能分成多少块&#xff1f;” Input 输入切的…

NVIDIA Tesla C2050 安装显卡驱动及cuda

参考官方指南 http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/index.html 1. 查看PCI接口 lspci | grep -i nvidia 2. 下载 wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_6.5-14_amd64.deb 3…

error C2050: switch expression not integral

#include<stdio.h> #include <string.h> char* test(); void main() { char* cRet test(); printf("Ret value:%s\n", &cRet); printf("retp:%p\n",cRet); if(!strcmp(cRet, "127.0.0.0")) { printf("返回值是127.0.0.0\n…

Word模板替换,并转PDF格式输出

Poi-tl参考文档地址&#xff1a;http://deepoove.com/poi-tl/1.8.x/#hack-loop-table word模板替换&#xff0c;转pdf 1. 依赖引入&#xff1a;2. word模板配置&#xff1a;3. 示例demo:4 . 效果图 1. 依赖引入&#xff1a; <dependency><groupId>org.apache.poi&…

SQLite简单使用

环境 操作系统&#xff1a;CentOS-7-x86_64-Everything-2009.iso 打开/创建指定数据库 sqlite3 mac.dbSQLite数据库内交互执行 # 查看所有数据库名 .databases # 查看所有表名 .tables # 附加数据库&#xff08;附加后可join查询&#xff09; ATTACH DATABASE ./mac.db as …

font-weight与ps字体粗细对应

UltraLight100 ThinExtraLight200 Light300 BookRegularNormal400 Medium500 DemiBoldSemiBold600 Bold700 ExtraBold800 HeavyBlackUltraUltraBlack900 FatExtraBlack1000

ps字体安装快捷安装方法

第一步&#xff1a;设置 打开控制面板&#xff0c;在右边搜索“字体”&#xff0c;即可打开字体文件夹&#xff0c;在左边&#xff0c;可以看到“字体设置” &#xff0c;打开&#xff1a; 勾选&#xff1a;允许使用快捷方式安装字体 第二步&#xff1a;快捷安装字体 打开下载…