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 ...
随机推荐
- android去除Spinner的分割线
<style name="TestSpinnerStyle" parent="android:style/Widget.ListView.DropDown" ...
- 摄像头的管理(camera) ---- HTML5+
模块:camera Camera模块管理设备的摄像头,可用于拍照.摄像操作,通过plus.camera获取摄像头管理对象. 应用场景:保存自拍,保存照片,上传照片,保存视频,上传视频: 通过之前的模块 ...
- 素数测试算法(基于Miller-Rabin的MC算法) // Fermat素数测试法
在以往判断一个数n是不是素数时,我们都是采用i从2到sqrt(n)能否整除n.如果能整除,则n是合数;否则是素数.但是该算法的时间复杂度为O(sqrt(n)),当n较大时,时间性能很差,特别是在网络安 ...
- Linux 搭建Nginx并添加配置 SSL 证书
1. 安装准备 1.1 gcc安装 安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装: [root@nginx ~]# yum -y i ...
- [面经] 南京SAP面试(下)
上一篇讲到了一面结束,这一篇说说剩下的事情. 周三上午一面完了之后回去上班,本以为要等几天才会二面,结果那个经理M下午就打电话给我,约了第二天(周四)下午过去面试,会有Boss从上海过来面,办事效率还 ...
- Spring应用配置文件上传的两种方案
欢迎查看Java开发之上帝之眼系列教程,如果您正在为Java后端庞大的体系所困扰,如果您正在为各种繁出不穷的技术和各种框架所迷茫,那么本系列文章将带您窥探Java庞大的体系.本系列教程希望您能站在上帝 ...
- js获取元素的外链样式
一般给元素设置行内样式,如<div id="div1" style="width:500px;"></div>.如要获取它的样式,即可d ...
- 【node】------node连接mongodb操作数据库------【巷子】
1.下载第三方模块mongodb cnpm install mongodb --save 2.检测是否连接成功 1.引入第三方模块mongodb并创建一个客户端 const MongoClient = ...
- 170807、intellij idea maven集成lombok实例
简介: lombok 通过简单注解方式简化java代码.(如消除实体对象的get/setter方法.日志对象声明等...) 安装步骤: 1.选择支持注解处理:Settings-->Build-- ...
- vue.js(三)
这里该记到vue的组件了,组件基础篇 1.vue组件的基本书写方式 Vue.component('button-counter', { data: function () { return { cou ...