1869: Mathematics and Geometry
这是郑州轻工业学校的一次校赛的校内选拔赛,看名字是计算几何 的题
题目地址:
http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1869
Description
给你一个n,求方程 2x + y + 2z = n 解的个数,其中x, y, z, n 都是非负整数
**********************以下是我的思路********************************
最开始的时候,我是想要用双重循环来做。枚举 x 和 y ,结果是肯定的 TLE
{ /* 代码我就不拿出来丢人了*/ }
{ /*中间的胡思乱想略去*/}
最后我想到了把方程放到 3维 的直角坐标系中 ,2x + y + 2z = n 其实是一个平面,而问题的解可以转化为在 “第一卦限内平面上整数点的个数”
巧的是 y 的系数是 1。于是把平面向 XZ 平面内投影(得到一个三角形区域,在这个三角形区域内的整数点都是平面上的整数点的投影),然后计算
XZ 二维平面上的三角形区域内的点的个数就是解。(更巧的是 x 和 z 的系数也是一样的,这样的话平面内点的计数就成了从 1 到(n/2 +1)的连续和,
如果 x 和 z 的系数不一样,那么解也应该是某个等差数列的和)
再说明一下,因为 y 的系数是1 ,所以才有 ”在这个三角形区域内的整数点都是平面上的整数点的投影“ (x 和 z 都是整数,n也是 ,那么 y=n-2*(x+z) 也是整数)
# include <stdio.h>
typedef long long int LL;
LL n,ans;
int t;
int main(){
scanf("%d",&t);
for(int i=0;i<t;++i){
scanf("%lld",&n);
n=n/2+1;
if(n%2==0){
ans=n/2*(n+1);
}else{
ans=(n+1)/2*n;
}
printf("Case #%d: %lld\n",i+1,ans);
}
return 0;
}
1869: Mathematics and Geometry的更多相关文章
- 第八届郑州轻工业学院ACM(程序设计大赛)校内预选赛
郑州轻工业学院有一个大赛,把几个有趣的题目分享一下.下面是题目连接,喜欢了就点点... 斗破苍穹 礼上往来 统计人数 神の数 炉石传说 Mathematics and Geometry 马拉松后记 斗 ...
- php实现var_dump函数
<?php class VarDump { private static $isInLoop = false; private static $buffer = false; public st ...
- What Is Mathematics?
What Is Mathematics? The National Council of Teachers of Mathematics (NCTM), the world's largest org ...
- <<Differential Geometry of Curves and Surfaces>>笔记
<Differential Geometry of Curves and Surfaces> by Manfredo P. do Carmo real line Rinterval I== ...
- Mathematics for Computer Graphics数学在计算机图形学中的应用 [转]
最近严重感觉到数学知识的不足! http://bbs.gameres.com/showthread.asp?threadid=10509 [译]Mathematics for Computer Gra ...
- How to do Mathematics
著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:匿名用户链接:http://www.zhihu.com/question/30087053/answer/47815698来源 ...
- Mathematics for Computer Graphics
Mathematics for Computer Graphics 最近严重感觉到数学知识的不足! http://bbs.gameres.com/showthread.asp?threadid=105 ...
- <Differential Geometry of Curves and Surfaces>(by Manfredo P. do Carmo) Notes
<Differential Geometry of Curves and Surfaces> by Manfredo P. do Carmo real line Rinterval I== ...
- How do I learn mathematics for machine learning?
https://www.quora.com/How-do-I-learn-mathematics-for-machine-learning How do I learn mathematics f ...
随机推荐
- 【原】SDWebImage源码阅读(三)
[原]SDWebImage源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1.SDWebImageDownloader中的downloadImageWithURL 我们 ...
- linux poll函数
poll函数与select函数差不多 函数原型: #include <poll.h> int poll(struct pollfd fd[], nfds_t nfds, int timeo ...
- js和jquery实现简单的选项卡
选项卡切换在做网页的时候经常会用到,以往都是用JQ来实现,代码简单易懂,今天用原生的js实现了一下,二者还是有很大不同的,可以对比一下代码来研究一下. <!DOCTYPE html> &l ...
- 谁是2016年的.NET开发者?
Nora Georgieva (http://www.telerik.com/blogs/infographic-the-dotnet-developer-of-2016) Whether you h ...
- JS / Egret 单笔手写识别、手势识别
UnistrokeRecognizer 单笔手写识别.手势识别 UnistrokeRecognizer : https://github.com/RichLiu1023/UnistrokeRecogn ...
- 使用MATLAB对图像处理的几种方法(下)
试验报告 一.试验原理: 图像点处理是图像处理系列的基础,主要用于让我们熟悉Matlab图像处理的编程环境.灰度线性变换和灰度拉伸是对像素灰度值的变换操作,直方图是对像素灰度值的统计,直方图均衡是对 ...
- html5 canvas常用api总结(一)
1.监听浏览器加载事件. window.addEventListener("load",eventWindowLoaded,false); load事件在html页面加载结束时发生 ...
- C#6新特性,让你的代码更干净
前言 前几天看一个朋友的博客时,看他用到了C#6的特性,而6出来这么长时间还没有正儿八经看过它,今儿专门看了下新特性,说白了也不过是语法糖而已.但是用起来确实能让你的代码更加干净些.Let's try ...
- CSS3属性 box-shadow 向框添加一个或多个阴影
CSS3属性 利用box-shadow制作网页页眉背景 box-shadow 浏览器支持 IE9+.Firefox 4.Chrome.Opera 以及 Safari 5.1.1 支持 box-shad ...
- VR/AR 非技术总结
VR/AR 非技术总结 **欢迎转载~转载请注明Erma的博客 http://www.cnblogs.com/Erma-king/** 都说2016是VR/AR的元年,上半年我随着新技术的潮流进入了V ...