SRM 585 DIV2
250pt:
一水...
500pt:
题意:
给你一颗满二叉树的高度,然后找出出最少的不想交的路径并且该路径每个节点只经过一次。
思路:
观察题目中给的图就会发现,其实每形成一个
就会存在一条路径。
我们只要求该满二叉树一共包含多少个即可。
注意奇数与偶数的不同,偶数要忽略第一个根节点,然后后边在+1
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define ll long long
#define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout); #define M 5007
#define N 1007
using namespace std; ll pow2[N];
void init()
{
for (int i = ; i <= ; ++i)
{
pow2[i] = (1LL<<i);
}
}
class TrafficCongestionDivTwo
{
public:
long long theMinCars(int n)
{
init();
ll ans = ;
if (n % == ) //奇数
{
for (int i = ; i < n; ++i)
{
if (i% == ) ans += pow2[i];
}
}
else //偶数
{ ans = 1LL;
for (int i = ; i < n; ++i)
{
if (i% == )
{
ans += pow2[i];
}
}
}
return ans;
} };
1000Pt:
给出一个长度为m的正方形,他的四边分别有不同的颜色的m-1个点均匀分布,然后正方形内有n个黑色的点,然后让你判断过正方形的不同的三条边上的点形成三角形使得该三角形包含所有的黑色的点,问一共有多少种画法?
思路:
我们首先枚举出任意两不同颜色的点看看所有的黑色的点是否其一侧,时间复杂度为O(n*n*m) ,然后枚举三角形判断该三角形是否包含所有黑色点即可。
#line 5 "EnclosingTriangleColorful.cpp"
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define ll long long
#define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define keyTree (chd[chd[root][1]][0])
#define Read() freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout); #define M 100
#define N 307 using namespace std; int dx[]={-,,,};
int dy[]={,,-,};//懈芯芯斜胁小褋褉 const int inf = 0x7f7f7f7f;
const int mod = ;
const double eps = 1e-; struct Point
{
double x,y;
Point(){}
Point(double tx = ,double ty = ) : x(tx),y(ty){}
};
typedef Point Vtor;
//鍚戦噺鐨勫姞鍑忎箻闄�
Vtor operator + (Vtor A,Vtor B) { return Vtor(A.x + B.x,A.y + B.y); }
Vtor operator - (Point A,Point B) { return Vtor(A.x - B.x,A.y - B.y); }
Vtor operator * (Vtor A,double p) { return Vtor(A.x*p,A.y*p); }
Vtor operator / (Vtor A,double p) { return Vtor(A.x/p,A.y/p); }
bool operator < (Point A,Point B) { return A.x < B.x || (A.x == B.x && A.y < B.y);}
int dcmp(double x){ if (fabs(x) < eps) return ; else return x < ? - : ; }
bool operator == (Point A,Point B) {return dcmp(A.x - B.x) == && dcmp(A.y - B.y) == ; }
//鍚戦噺鐨勭偣绉紝闀垮害锛屽す瑙�
double Dot(Vtor A,Vtor B) { return A.x*B.x + A.y*B.y; }
double Length(Vtor A) { return sqrt(Dot(A,A)); }
double Angle(Vtor A,Vtor B) { return acos(Dot(A,B)/Length(A)/Length(B)); }
double Cross(Vtor A,Vtor B) { return A.x*B.y - A.y*B.x; }
double Area2(Point A,Point B,Point C) { return Cross(B - A,C - A); } bool UL[N][N],UR[N][N],DL[N][N],DR[N][N];
bool LR_up[N][N],LR_dw[N][N],UD_L[N][N],UD_R[N][N]; class EnclosingTriangleColorful
{
public:
int getNumber(int m, vector <int> x, vector <int> y)
{
int n = x.size();
//鍑轰簨璇濅笁瑙掑舰鐨勮竟
//涓婏紝宸︼紝鍙�
for (int i = ; i < m; ++i)
{
for (int j = ; j < m; ++j)
{
bool f1 = true ,f2 = true;
for (int k = ; k < n; ++k)
{
Point A(i,m);
Point B(,j);
Point C(m,j);
if (Cross(B - A,Point(x[k],y[k]) - A) < ) f1 = false;
if (Cross(C - A,Point(x[k],y[k]) - A) > ) f2 = false;
}
UL[i][j] = f1; UR[i][j] = f2;
}
}
//涓�宸︼紝鍙�
for (int i = ; i < m; ++i)
{
for (int j = ; j < m; ++j)
{
bool f1 = true ,f2 = true;
for (int k = ; k < n; ++k)
{
Point A(i,);
Point B(,j);
Point C(m,j);
if (Cross(B - A,Point(x[k],y[k]) - A) > ) f1 = false;
if (Cross(C - A,Point(x[k],y[k]) - A) < ) f2 = false;
}
DL[i][j] = f1; DR[i][j] = f2;
}
}
//宸︼紝鍙�
for (int i = ; i < m; ++i)
{
for (int j = ; j < m; ++j)
{
bool f1 = true ,f2 = true;
for (int k = ; k < n; ++k)
{
Point A(,i);
Point B(m,j);
if (Cross(B - A,Point(x[k],y[k]) - A) < ) f1 = false;
if (Cross(B - A,Point(x[k],y[k]) - A) > ) f2 = false;
}
LR_up[i][j] = f1; LR_dw[i][j] = f2;
}
}
//涓婏紝涓�
for (int i = ; i < m; ++i)
{
for (int j = ; j < m; ++j)
{
bool f1 = true ,f2 = true;
for (int k = ; k < n; ++k)
{
Point A(i,m);
Point B(j,);
if (Cross(B - A,Point(x[k],y[k]) - A) > ) f1 = false;
if (Cross(B - A,Point(x[k],y[k]) - A) < ) f2 = false;
}
UD_L[i][j] = f1; UD_R[i][j] = f2;
}
} int ans = ;
//涓婂乏鍙�
for (int i = ; i < m; ++i)
{
for (int j = ; j < m; ++j)
{
for (int k = ; k < m; ++k)
{
if (UL[i][j] && UR[i][k] && LR_up[j][k]) ans++;
}
}
}
//涓嬪乏鍙�
for (int i = ; i < m; ++i)
{
for (int j = ; j < m; ++j)
{
for (int k = ; k < m; ++k)
{
if (DL[i][j] && DR[i][k] && LR_dw[j][k]) ans++;
}
}
}
//宸︿笂涓�
for (int i = ; i < m; ++i)
{
for (int j = ; j < m; ++j)
{
for (int k = ; k < m; ++k)
{
if (UL[j][i] && DL[k][i] && UD_L[j][k]) ans++;
}
}
}
//鍙充笂涓�
for (int i = ; i < m; ++i)
{
for (int j = ; j < m; ++j)
{
for (int k = ; k < m; ++k)
{
if (UR[j][i] && DR[k][i] && UD_R[j][k]) ans++;
}
}
}
return ans; } }; // Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor
SRM 585 DIV2的更多相关文章
- SRM 657 DIV2
-------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...
- Topcoder Srm 673 Div2 1000 BearPermutations2
\(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...
- Topcoder Srm 671 Div2 1000 BearDestroysDiv2
\(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...
- 记第一次TopCoder, 练习SRM 583 div2 250
今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...
- Topcoder srm 632 div2
脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...
- SRM 638 Div2
2333... 因为TC过少的参与者.加上不断fst 我掉了div2该. 幸运的是完成的背div1该.. 250 水的问题 500 水的问题.. 直接bfs扩展即可了 注意判重. 我还用康托展开了真 ...
- SRM 592 DIV2 报告
昨天下午查看邮箱,看到了topcoder的SRM比赛通知和cf的比赛通知,当时什么也不想做,心里空荡荡的,忽然就想参加一下,试试看.吃完晚饭回来一看,就剩十几分钟了,匆忙把平台下了,就开始等待比赛开始 ...
- SRM 670 div2 A B C div1 A(贪心,子问题合并)
A Cdgame brute force... B Drbalance 贪心,每次选最前面的-变成+,相当于后面所有的负值+2. C Treestrat 考虑集中去抓一个Red Token,以这个To ...
- topcpder SRM 664 div2 A,B,C BearCheats , BearPlays equalPiles , BearSorts (映射)
A题,熊孩子测视力,水题,题意就是判断一下两个数对应位不相同的数字有多少个. #include<bits/stdc++.h> using namespace std; class Bear ...
随机推荐
- 【BZOJ4556】[Tjoi2016&Heoi2016]字符串 后缀数组+二分+主席树+RMQ
[BZOJ4556][Tjoi2016&Heoi2016]字符串 Description 佳媛姐姐过生日的时候,她的小伙伴从某东上买了一个生日礼物.生日礼物放在一个神奇的箱子中.箱子外边写了一 ...
- Redis对于key的操作命令
del key1 key2 ... Keyn 作用: 删除1个或多个键 返回值: 不存在的key忽略掉,返回真正删除的key的数量 rename key newkey 作用: 给key赋一个新的ke ...
- 三维凸包求重心到面的最短距离(HDU4273)
http://acm.hdu.edu.cn/showproblem.php?pid=4273 Rescue Time Limit: 2000/1000 MS (Java/Others) Memo ...
- python-social-auth with Django: ImportError: No module named 'social_django' 解决方法
To use Django with python social auth, you need to install the Django app as well. You can specify t ...
- HRBUST - 1153 意外 HRBUST - 1153 (数论)
意外 Time Limit: 1000 MS Memory Limit: 65536 K Total Submit: 326(87 users) Total Accepted: 97(63 users ...
- poj1584 A round peg in a ground hole【计算几何】
含[判断凸包],[判断点在多边形内],[判断圆在多边形内]模板 凸包:即凸多边形 用不严谨的话来讲,给定二维平面上的点集,凸包就是将最外层的点连接起来构成的凸多边形,它能包含点集中所有的点. The ...
- wget全站抓取命令
wget -r -p -np -k http://www.freebuf.com/ 忽视,避开robots.txt,加一个-e robots=off 用wget避开robots.txt的下载限制 wg ...
- oracle 安装,登陆,配置
1:查看: https://blog.csdn.net/u014177640/article/details/71023380/ 2:登陆 https://zhidao.baidu.com/ques ...
- Spark提交应用程序之Spark-Submit分析
1.提交应用程序 在提交应用程序的时候,用到 spark-submit 脚本.我们来看下这个脚本: if [ -z "${SPARK_HOME}" ]; then export S ...
- 入坑-DM导论-第一章绪论笔记
//本学习笔记只是记录,并未有深入思考. 1.什么是数据挖掘? 数据挖掘是数据库中发现必不可少的一部分. 数据预处理主要包括(可能是最耗时的步骤): 1.融合来自多个数据源的数据 2.清洗数据以消除噪 ...