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 ...
随机推荐
- 河南省第七届ACM程序设计大赛总结
省赛总结 首先说说比赛时的情况吧,刚开始的时候我的任务就是翻译英文题目,找出比较水的题目,他们两个直接找中文水题切,其实每次比赛我们都是这样配合的,由于他们的判题系统一开始存在问题,交的正确的代码给判 ...
- CodeForces Roads not only in Berland(并查集)
H - Roads not only in Berland Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
- SQL---->mySQl查看和更改端口
修改端口: 采用dmg方式安装的mysql,默认启动端口为3307,不是默认的3306.如果想改为3306,可以编辑 /Library/LaunchDaemons /com.Oracle.os ...
- Scala简介及基础语法
一.scala简介 官网:https://www.scala-lang.org/ Scala语言很强大,集成了面向对象和函数式编程的特点. 运行在JVM(jdk). 大数据中为什么学习scala? s ...
- HTML实例 - 购物商场页面
效果图 代码 https://coding.net/u/James_Lian/p/Shopping-page/git 示例 https://coding.net/u/James_Lian/p/Shop ...
- mysql 数据操作 单表查询 where约束 工作模式
select name,age from employee where id >7; 1.首先先找到表 from employee 2.表存在 mysql拿着约束条件 去表里 看依次匹配数 ...
- centos LNMP第一部分环境搭建 LAMP LNMP安装先后顺序 php安装 安装nginx 编写nginx启动脚本 懒汉模式 mv /usr/php/{p.conf.default,p.conf} php运行方式SAPI介绍 第二十三节课
centos LNMP第一部分环境搭建 LAMP安装先后顺序 LNMP安装先后顺序 php安装 安装nginx 编写nginx启动脚本 懒汉模式 mv /usr/local/php/{ ...
- JAVA 线程状态转换
Thread类中State枚举定义: public enum State { /** * Thread state for a thread which has not yet started. */ ...
- Spring源码解析(五)循环依赖问题
引言 循环依赖就是多个类之间互相依赖,比如A依赖B,B也依赖A,如果日常开发中我们用new的方式创建对象,这种循环依赖就会导致不断的在创建对象,导致内存溢出. Spring是怎么解决循环依赖的问题的? ...
- 使用JavaScript修改浏览器URL地址栏的实现代码
现在的浏览器里,有一个十分有趣的功能,你可以在不刷新页面的情况下修改浏览器URL;在浏览过程中.你可以将浏览历史储存起来,当你在浏览器点击后退按钮的时候,你可以冲浏览历史上获得回退的信息,这听起来并不 ...