TopCoder[SRM587 DIV 1]:TriangleXor(550)
Problem Statement |
|||||||||||||
You are given an int W. There is a rectangle in the XY-plane with corners at (0, 0), (0, 1), (W, 0), and (W, 1). Let T[x] be the triangle with vertices at (0, 1), (W, 1) and (x, 0). (All points that lie inside the triangle are a part of T[x] as well.) The objective in this problem is to calculate the area of the region (T[0] xor T[1] xor ... xor T[W]). (See Notes for a formal definition.) The figures below show the region (T[0] xor T[1] xor ... xor T[W]) for W=1,2,3,4,5,6.
Return the integer part of the area of the region. |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Limits |
|||||||||||||
|
|||||||||||||
Notes |
|||||||||||||
- | For sets of points A and B in the XY-plane, the set (A xor B) is defined as the set of all points that lie in exactly one of the sets A and B (i.e., points that belong to the union of A and B but don't belong to their intersection). | ||||||||||||
- | If the exact area is A, the correct return value is floor(A), not round(A). In words: you should return the largest integer that is less than or equal to the exact area. | ||||||||||||
- | The format of the return value was chosen to help you in case of small precision errors. The constraints guarantee that computing the correct area with absolute error less than 0.01 is sufficient to determine the correct return value. The author's solution is significantly more precise than that. | ||||||||||||
Constraints |
|||||||||||||
- | W will be between 1 and 70,000, inclusive. | ||||||||||||
- | The difference between the exact area of the region and the nearest integer will be greater than 0.01. | ||||||||||||
Examples |
|||||||||||||
0) | |||||||||||||
|
|||||||||||||
1) | |||||||||||||
|
|||||||||||||
2) | |||||||||||||
|
|||||||||||||
3) | |||||||||||||
|
|||||||||||||
4) | |||||||||||||
|
|||||||||||||
5) | |||||||||||||
|
题意:给你一个1*n的矩形,按图中方法划线、涂色,问多大面积涂为黄色。
题解:
根据题目中的图,可以用两条对角线把涂色区域分为四个部分。
对于上方部分,若n为偶数,全为黄色;若为奇数,全为黑色。
对于左右部分,通过三角形的相似求出各个等高三角形的底之和与对角线长度的比例,计算面积。
对于下方部分,同样通过相似求出各组等高四边形的底之和与高,计算面积。
代码:
class JumpFurther
{
public:
int furthest(int N, int badStep)
{
//$CARETPOSITION$
int tot=,x=;
for(int i=;i<=N;i++)
{
tot=tot+i; if(tot==badStep)x--;
}
return tot+x;
}
};
TopCoder[SRM587 DIV 1]:TriangleXor(550)的更多相关文章
- TopCoder[SRM587 DIV 1]:ThreeColorability(900)
Problem Statement There is a H times W rectangle divided into unit cells. The rows of cells are ...
- TopCoder[SRM513 DIV 1]:Reflections(1000)
Problem Statement Manao is playing a new game called Reflections. The goal of the game is trans ...
- Topcoder SRM584 DIV 2 500
#include <set> #include <iostream> #include <string> #include <vector> using ...
- Topcoder SRM583 DIV 2 250
#include <string> #include <iostream> using namespace std; class SwappingDigits { public ...
- 【补解体报告】topcoder 634 DIV 2
A:应该是道语文题,注意边界就好: B:开始考虑的太复杂,没能够完全提取题目的思维. 但还是A了!我愚蠢的做法:二分答案加暴力枚举, 枚举的时候是完全模拟的,比如每次取得时候都是从大到小的去取,最后统 ...
- Topcoder Srm627 DIV 2
A,B:很水,注意边界,话说HACK都是这些原因. C: R[I][J]:表示反转I-J能改变冒泡排序的次数: DP方程:dp[i][k]=max(dp[j][k],dp[j][k-1]+dp[j][ ...
- Topcoder SRM548 Div 1
1. KingdomAndTrees 给出n个数a[1..n],求一个数组b[1..n]满足b严格递增,且b[1]>=1. 定义代价为W = max{abs(a[i]-b[i])},求代价最小值 ...
- TopCoder[SRM513 DIV 1]:PerfectMemory(500)
Problem Statement You might have played the game called Memoria. In this game, there is a board ...
- [topcoder]BinaryCards
现在觉得有空时可以刷一下topcoder的DIV 2的Lvl 3的题目.感觉和刷LeetCode和WikiOi都是不一样的. http://community.topcoder.com/stat?c= ...
随机推荐
- 一篇不一样的Android屏幕适配具体做法(原创)
转载请注明出处(http://www.cnblogs.com/weizhxa/p/7568090.html ) 有不正确,还请大家留言修正! 1.何谓屏幕适配:在任何设备上看起来布局都是近似的,细分也 ...
- C++中的delete加深认识
delete操作: 我们在删除一个指针之后,编译器只会释放该指针所指向的内存空间,而不会删除这个指针本身. 1.假如你不去释放,那么该区域的内存始终不能被其他数据所使用.2.指向该内存的指针是个局部变 ...
- HBase封装easy-hbase设计实现
新增码云地址:https://gitee.com/hanmov5/mop-hbase-template 一.写在前面 业务架构用到HBase,但由于某些不可名状原因,没有用phoniex等上层工具,开 ...
- 排序+并查集——cf1213F
/* 有向边(pi,pi+1),形成链后进行dfs,求出dfs序 一个联通块内的元素必须是同一个字符,如果最后的联通块个数<k,说明不行 */ #include<bits/stdc++.h ...
- 谈html mailto(电子邮件)实际应用
大家知道,mailto是网页设计制作中的一个非常实用的html标签,许多拥有个人网页的朋友都喜欢在网站的醒目位置处写上自己的电子邮件地址,当点击时就能自动打开当前计算机系统中默认的电子邮件客户端软件, ...
- thinkphp 表单令牌
表单令牌 ThinkPHP支持表单令牌验证功能,可以有效防止表单的重复提交等安全防护.要启用表单令牌功能,需要配置行为绑定, 在应用或者模块的配置目录下面的行为定义文件tags.php中 就是在你的 ...
- 杂项-PPT:如何把幻灯片ppt转换成视频
ylbtech-杂项-PPT:如何把幻灯片ppt转换成视频 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 1. https://jingyan.baidu.co ...
- hexo的next主题博客中加入分类页面的js,实现多级目录,并且能够点击展开,隐藏下级目录~(不知道算不算深度优化~~~)
个人博客:https://mmmmmm.me 源码:https://github.com/dataiyangu/dataiyangu.github.io 多级标题 在自己的xxxx.md文件中做如下修 ...
- 18、Linux命令对服务器CPU进行监控
我刚开始做性能测试的时候,什么也不懂,就只知道压测.什么时候把系统压瘫痪什么时候结束.但是系统因为什么瘫痪却不是很清楚,后来开始研究服务器性能监控,运用到工作中,提高了不少生产力,下面就把我常用的命令 ...
- synchronized与ReenTranLock的区别
1.synchronized 回顾 表示原子性和可见性 原子性:一次只有一个线程能执行lock保护的代码 可见性:线程更新了变量后会将其更新到主内存里面 volatile可以实现可见性,不能实现原子性 ...