topcoder srm 703 div1 -3
1、给出一个包含$n$个元素的数组$x$,构造出一个有向无环图满足从节点$i$出发可以访问到的节点数为$x_{i}$。
思路:按照$x$从小到大排序。然后从前向后处理,当前节点依次与前面已经处理的节点连边。
#include <iostream>
#include <map>
#include <string>
#include <stdio.h>
#include <vector>
#include <set>
#include <algorithm>
#include <string.h>
#include <fstream>
#include <sstream>
using namespace std; const int N=555;
const int mod=998244353; int get(long long x)
{
int cnt=0;
for(int i=0;i<55;++i)
{
if(x&(1ll<<i)) ++cnt;
}
return cnt;
} class DAGConstruction
{
public:
vector <int> construct(vector <int> x)
{
const int n=(int)x.size();
long long f[55];
memset(f,0,sizeof(f));
vector<int> ans,V;
vector<pair<int,int>> p;
for(int i=0;i<n;++i)
{
f[i]=1ll<<i;
p.push_back(make_pair(x[i],i));
}
sort(p.begin(),p.end());
for(int i=0;i<(int)p.size();++i)
{
int c=p[i].first;
int u=p[i].second;
for(int j=0;j<(int)V.size();++j)
{
int t=V[V.size()-1-j];
if(get(f[u]|f[t])<=c)
{
f[u]|=f[t];
ans.push_back(u);
ans.push_back(t);
}
}
V.push_back(u);
if(get(f[u])<c) return vector<int>(1,-1);
}
return ans;
}
};
2、在$x$ 轴上有$n$个点A,$x$轴上方有$n$个点B,A集合中的每个点在B集合中的每个点找到一个匹配点,B集合中每个点只能与A中的一个点匹配,使得$n$条线段任意两条线段不相交。问有多少种方法。
思路:将B集合按照$y$坐标排序。A集合按照$x$排序。每次枚举A中的一个点与B中最高的点连线,这样分成两段,继续进行这样的匹配。
#include <iostream>
#include <map>
#include <string>
#include <stdio.h>
#include <vector>
#include <set>
#include <algorithm>
#include <string.h>
#include <fstream>
#include <sstream>
using namespace std; const int N=555;
const int mod=1000000007; vector<int> D,X,Y;
int n; map<vector<int>,int> mp[55][55]; int dfs(int L,int R,vector<int> S)
{ if(S.size()<=1) return 1;
if(mp[L][R].count(S)) return mp[L][R][S]; long long ans=0;
for(int i=L;i<=R;++i)
{ const int x1=X[S.back()]-D[i];
const int y1=Y[S.back()];
vector<int> ls,rs;
int ok=1;
for(int j=0;j<(int)S.size()-1;++j)
{
const int x0=X[S[j]]-D[i];
const int y0=Y[S[j]];
const int sgn=x0*y1-x1*y0;
if(sgn==0)
{
ok=0;
break;
}
if(sgn<0) ls.push_back(S[j]);
else rs.push_back(S[j]);
}
if(ok&&ls.size()==i-L&&rs.size()==R-i) ans+=1ll*dfs(L,i-1,ls)*dfs(i+1,R,rs)%mod;
}
return mp[L][R][S]=ans%mod;
} class CoastGuard
{
public:
int count(vector <int> d, vector <int> x, vector <int> y)
{
n=(int)d.size();
D=d;
sort(D.begin(),D.end());
vector<pair<int,int>> p;
vector<int> S;
for(int i=0;i<n;++i)
{
p.push_back(make_pair(y[i],x[i]));
S.push_back(i);
}
sort(p.begin(),p.end());
for(int i=0;i<n;++i)
{
Y.push_back(p[i].first);
X.push_back(p[i].second);
}
return dfs(0,n-1,S);
}
};
topcoder srm 703 div1 -3的更多相关文章
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- topcoder srm 714 div1
problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...
- topcoder srm 738 div1 FindThePerfectTriangle(枚举)
Problem Statement You are given the ints perimeter and area. Your task is to find a triangle wi ...
- Topcoder SRM 602 div1题解
打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...
- Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串
Problem Statement The Happy Letter game is played as follows: At the beginning, several players ...
- Topcoder SRM 584 DIV1 600
思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...
- TopCoder SRM 605 DIV1
604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...
- topcoder srm 575 div1
problem1 link 如果$k$是先手必胜那么$f(k)=1$否则$f(k)=0$ 通过对前面小的数字的计算可以发现:(1)$f(2k+1)=0$,(2)$f(2^{2k+1})=0$,(3)其 ...
随机推荐
- centos7上安装nodejs
1. 确保安装编译工具 $ yum -y install gcc gcc-c++ 2. 获取官网源码 : $ wget https://nodejs.org/dist/v9.9.0/node-v9.9 ...
- struts2启动时,出现的com.opensymphony.xwork2.util.finder.ClassFinder - Unable to read class 错误解决办法
在项目的struts.xml文件中第一行加入<constant name="struts.convention.package.locators" value="c ...
- CentOS双机中Docker下安装Mysql并配置互为主从模式
CentOS双机中Docker下安装Mysql并配置互为主从模式 目录 1.搜索镜像... 1 2.拉取镜像... 1 3.绑定端口: 1 4.配置文件(修改/etc/mysql/my.cnf文件): ...
- sql server 中DateName()函数及DatePart()函数
Datepart():返回代表指定日期的指定日期部分的整数 语法:Datepart(datepart,date) 返回类型:int DateName():返回代表指定日期的指定日期部分的字符串 语法 ...
- mysql优化(二)
一.客户端分担. 1.大量的复杂的运算放在客户端处理. 什么是复杂运算,一般我认为是一秒钟CPU只能做10万次以内的运算.如含小数的对数及指数运算.三角函数.3DES及BASE64数据加密算法等等.如 ...
- Attention Is All You Need 一些好的资料
The encoders are all identical in structure (yet they do not share weights). Each one is broken down ...
- 随机模拟(MCMC)
http://cos.name/2013/01/lda-math-mcmc-and-gibbs-sampling/ http://blog.csdn.net/lin360580306/article/ ...
- RSA解密解密
#!/usr/bin/env python # -*- coding:utf-8 -*- import rsa import base64 # ######### 1. 生成公钥私钥 ######## ...
- ResourceBundle与Properties读取配置文件
ResourceBundle与Properties的区别在于ResourceBundle通常是用于国际化的属性配置文件读取,Properties则是一般的属性配置文件读取. ResourceBundl ...
- Linux基础命令---iptables-save
iptables-save iptables-save指令可以将内核中当前的iptables配置导出到标准输出.通过IO重定向功能来定向输出到文件. 此命令的适用范围:RedHat.RHEL.Ubun ...