hackerrank Project Euler #210: Obtuse Angled Triangles

2023-10-21 22:10

本文主要是介绍hackerrank Project Euler #210: Obtuse Angled Triangles,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

传送门
做出一个好几个星期屯下来的题目的感觉就是一个字:
爽!
1324872-20180531195115031-1818228875.png
上图的黄点部分就是我们需要求的点

两边的部分很好算
求圆的地方有一个优化,由于圆心是整数点,我们可以把圆分为下面几个部分,阴影部分最难算,最后乘就好了

1324872-20180531212734260-1408262614.jpg

代码如下所示

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef long double Double;
const Double tiny = 1e-20;ll Ceil(Double x) {ll tt = ceil(x);if(abs(tt - x) < tiny) tt ++;return tt;
}ll Floor(Double x) {ll tt = floor(x);if(abs(tt - x) < tiny) tt --;return tt;
}int main() {
#ifdef LOCALfreopen("in.txt", "r", stdin);
#endifint r, a, b, n;while(~scanf("%d %d %d %d", &r, &a, &b, &n)) {Double leftEdge = Double(a*1.0)/b;Double rightEdge = 2*n - Double(a*1.0)/b;Double radiusTo2 = n - Double(a*1.0)/b;if(leftEdge > rightEdge) swap(leftEdge, rightEdge); ll sum = 0;Double leftDouble = r + 2*leftEdge;int leftInt = ceil(leftDouble);Double rightDouble = r - 2*rightEdge;int rightInt = ceil(rightDouble);sum += 1ll * (rightInt + leftInt) * r;if(rightInt % 2) sum += r & 1;if(leftInt % 2) sum += r & 1;// printf("%d %d %lld\n", leftInt, rightInt, sum);Double cirRadius = (rightEdge - leftEdge) / sqrt(2);// printf("%.3f\n", cirRadius);ll tmpSum = 0;for(int i = Floor(cirRadius), edge = ceil(radiusTo2); i >= edge; --i) {tmpSum += Floor(sqrt( (rightEdge - leftEdge)*(rightEdge - leftEdge) / 2 - 1ll*i*i));// tmpSum += Floor(sqrt( cirRadius * cirRadius - 1ll*i*i));}sum += tmpSum * 8;// printf("%lld\n", sum);sum += 1ll * Floor(cirRadius) * 4;// printf("%lld\n", sum);// printf("%.9f\n", (rightEdge - leftEdge)/2.0);sum += 1ll* Floor(radiusTo2) * Floor(radiusTo2) * 4;sum -= 1ll * Floor(n - leftEdge) * 2;printf("%lld\n", sum);}return 0;
} 

转载于:https://www.cnblogs.com/Basasuya/p/9118740.html

这篇关于hackerrank Project Euler #210: Obtuse Angled Triangles的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/257285

相关文章

Debugging Lua Project created in Cocos Code IDE creates “Waiting for debugger to connect” in Win-7

转自 I Installed Cocos Code IDE and created a new Lua Project. When Debugging the Project(F11) the game window pops up and gives me the message waiting for debugger to connect and then freezes. Also a

SVN Cornerstone 报错信息 xcodeproj cannot be opened because the project file cannot be parsed.

svn点击update 之后,打开xcode工程文件,会出现  xxx..xcodeproj  cannot be opened because the project file cannot be parsed. 发现项目中代码全没了。只有一个空的工程名字,因为xcodeproj工程文件冲突了,然后就是svn强制给你更新了,内部的文件冲突了,你们改了同样的地方的一段代码,可能是你们只是多加

Android Studio打开Modem模块出现:The project ‘***‘ is not a Gradle-based project

花了挺长时间处理该问题,特记录如下:1.背景: 在Android studio 下导入一个新增的modem模块,如MPSS.DE.3.1.1\modem_proc\AAA, 目的是看代码方便一些,可以自由搜索各种关键字。但导入该项目时出现了如下错误: The project '***' is not a Gradle-based project.造成的问题: (1) project 下没有代码,而

实习四十:部署project_exam_system项目——及容器的编排

(一)安装docker、编辑daemon.json文件、安装docker-compose编排容器、启动docker 1.环境准备 [root@docker--1 ~]# rz -E   rz waiting to receive.   [root@docker--1 ~]# ls   anaconda-ks.cfg  docker.sh   [root@docker--1 ~]# source

【UVa】 10735 Euler Circuit 混合图的欧拉回路 最大流

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1676 题目要求:求混合图的欧拉回路+输出路径。 题目分析: 先看一段比较流行的说法吧~: -----------------------------------------

解决Re-download dependencies and sync project

解决Re-download dependencies and sync project 问题描述 新建一个工程,报错 Error:Failed to open zip file.Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)<a hr

myEclipse刚打开启动报Errors running builder 'DeploymentBuilder' on project '工程名' xxxNullpointException 的错误

 早上打开myEclipse就会报 Errors running builder 'DeploymentBuilder' on project '工程名' xxxNullpointException 的错误。找了半天,也没有解决方法。终于找到一个看似靠谱的博客 http://5666522.blog.51cto.com/5656522/1238898    解决了该问题 解决方法如

idea的maven project消失解决方案

方案一:点击菜单栏View->Tool Windows->Maven projects 方案二:File -> Settings -> Plugins -> Installed ->找到下面两个并勾选->然后重启 1,Maven Integration 2,Maven Integration Extension