传送门

做出一个好几个星期屯下来的题目的感觉就是一个字:

爽!



上图的黄点部分就是我们需要求的点

两边的部分很好算

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

代码如下所示

#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 LOCAL
freopen("in.txt", "r", stdin);
#endif int 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;
}

hackerrank Project Euler #210: Obtuse Angled Triangles的更多相关文章

  1. Project Euler 94:Almost equilateral triangles 几乎等边的三角形

    Almost equilateral triangles It is easily proved that no equilateral triangle exists with integral l ...

  2. Project Euler 91:Right triangles with integer coordinates 格点直角三角形

    Right triangles with integer coordinates The points P (x1, y1) and Q (x2, y2) are plotted at integer ...

  3. Project Euler 39 Integer right triangles( 素勾股数 )

    题意:若三边长 { a , b , c } 均为整数的直角三角形周长为 p ,当 p = 120 时,恰好存在三个不同的解:{ 20 , 48 , 52 } , { 24 , 45 , 51 } , ...

  4. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  5. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  6. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  7. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  8. project euler 169

    project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...

  9. 【Project Euler 8】Largest product in a series

    题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...

随机推荐

  1. APICloud的App怎么在手机上测试运行

    方式一: 工程->右键->云编译自定义 AppLoader,如图: 点击[编译iOS自定义loader]或者[编译Android自定义loader],会生成相应的二维码,手机扫描二维码点击 ...

  2. [转]ASP.NET如何获取上传图片尺寸(是指宽高)

    1.采用客户端javascript可以取得图片大小 <input id="FileUpload" type="file" size="27&qu ...

  3. 2018年暑假ACM个人训练题6 解题报告

    A:水题 https://www.cnblogs.com/yinbiao/p/9311834.html B:考察进制的转化 https://www.cnblogs.com/yinbiao/p/9311 ...

  4. Gradle Goodness: Running Java Applications from External Dependency

    With Gradle we can execute Java applications using the JavaExec task or the javaexec() method. If we ...

  5. JAVA并发-线程状态

    一.线程基本状态 新建:线程已创建但start()方法还没执行 就绪(可运行):start()方法已运行,但还没被选择 运行:从就绪线程中选择出某一个线程进行run()操作 阻塞(不可运行):线程正在 ...

  6. Oracle分区表删除分区引发错误ORA-01502: 索引或这类索引的分区处于不可用状态

    (一)问题: 最近在做Oracle数据清理,在对分区表进行数据清理时,采用的方法是drop partition,删除的过程中,没有遇到任何问题,大概过了10分钟,开发人员反馈部分分区表上的业务失败.具 ...

  7. var let const的一些区别

    var let const 都是来定义变量的. var let 作用域有些区别. const 类似于java中的常量的概念.即:只能给一个变量赋值一次,即指定一个引用. 举例来说: function ...

  8. npm常见配置收集

    npm代理设置为走ss通道:npm config set proxy 'http://localhost:1080'

  9. Web移动端商城 移动端商城手机网站html整套模板,web移动商城仿app手机模板下载

    --Web移动端商城移动端商城手机网站html整套模板,web移动商城仿app手机模板下载.原生的js和jquery-1.6.2.min.js,页面才有html5自适应.包括首页(轮播,导航).兼职( ...

  10. hadoop生态搭建(3节点)-10.spark配置

    # https://www.scala-lang.org/download/2.12.4.html# ================================================= ...