topcoder srm 698 div1 -3
1、定义重复串$S=T+T$,即$S$可以表示成一个串的叠加。给定一个串$s$,可以通过删除字符、修改字符、增加字符来使得其变为重复串。问最少的次数。
思路:首先将$s$分成个串$s_{0},s_{1}$,然后计算将$s_{0},s_{1}$变成一样要多少次操作。
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <assert.h>
using namespace std; int f[111][111]; void up(int &x,int y)
{
if(x==-1||x>y) x=y;
} int cal(string s1,string s2)
{
const int n=(int)s1.size();
const int m=(int)s2.size(); if(n==0) return m;
if(m==0) return n; memset(f,-1,sizeof(f));
f[0][0]=0;
for(int i=1;i<=m;++i) f[0][i]=i;
for(int i=1;i<=n;++i) f[i][0]=i; for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
char c1=s1[i-1];
char c2=s2[j-1];
up(f[i][j],f[i-1][j]+1);
up(f[i][j],f[i][j-1]+1);
up(f[i][j],f[i-1][j-1]+(c1!=c2));
}
}
return f[n][m];
} class RepeatString
{
public:
int minimalModify(string s)
{
const int n=(int)s.size();
int ans=n;
for(int i=0;i<=n;++i)
{
ans=min(ans,cal(s.substr(0,i),s.substr(i)));
}
return ans;
}
};
2、给出平面上$n$个点的集合$S$,没有三点共线。定义$CH(s)$为包含点集$s$的最小凸包。求这样的点集对$(s_{1},s_{2})$有多少:(1)$s_{1}\in S,s_{2} \in S$;(2)$s_{1},s_{2}$没有交集;(3)$CH(s_{1}),CH(s_{2})$相交。
思路:求出所有的点集对然后减去不相交的。不相交的可以通过枚举两个点$p_{0},p_{1}$来确定一条直线,然后从直线一侧选出一些点跟$p_{0}$组成一个点集,从直线另一侧选出一些点跟$p_{1}$组成一个点集。
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <assert.h>
using namespace std; const int N=111;
const int mod=1000000007; int C[N][N],p[N]; void init()
{
C[0][0]=1;
for(int i=1;i<N;++i)
{
C[i][0]=C[i][i]=1;
for(int j=1;j<i;++j)
{
C[i][j]=C[i-1][j]+C[i-1][j-1];
if(C[i][j]>=mod) C[i][j]-=mod;
}
} p[0]=1;
for(int i=1;i<N;++i)
{
p[i]=p[i-1]<<1;
if(p[i]>=mod) p[i]-=mod;
}
} class IntersectingConvexHull
{
public:
int count(vector <int> x, vector <int> y)
{
init();
const int n=(int)x.size();
int ans=0;
for(int i=3;i<=n;++i) for(int j=3;j<=n-i;++j)
{
ans+=(long long)C[n][i]*C[n-i][j]%mod;
if(ans>=mod) ans-=mod;
}
for(int i=0;i<n;++i) for(int j=0;j<n;++j) if(i!=j)
{
int s[2]={0,0};
for(int k=0;k<n;++k) if(k!=i&&k!=j)
{
long long d=(long long)(x[j]-x[i])*(y[k]-y[i])-(long long)(x[k]-x[i])*(y[j]-y[i]);
if(d>0) ++s[0];
else ++s[1];
}
if(s[0]<2||s[1]<2) continue; int t0=p[s[0]]-1-s[0];
int t1=p[s[1]]-1-s[1];
ans-=(long long)t0*t1%mod;
if(ans<0) ans+=mod;
}
return ans;
}
}; int main()
{ IntersectingConvexHull p;
printf("%d\n",p.count({-2,-1,-1,1,1,2},{1,0,2,0,2,1}));
}
topcoder srm 698 div1 -3的更多相关文章
- Topcoder SRM 698 Div1 250 RepeatString(dp)
题意 [题目链接]这怎么发链接啊..... Sol 枚举一个断点,然后类似于LIS一样dp一波 这个边界条件有点迷啊..fst了两遍... #include<bits/stdc++.h> ...
- 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 ...
随机推荐
- (3)Python3笔记之变量与运算符
一.变量 1). 命名规则: 1. 变量名不能使用系统关键字或保留关键字 2. 变量区分大小写 3. 变量命名由字母,数字,下划线组成但不能以数字开头 4. 不需要声明变量类型 是 a = 1 ...
- Mongodb $in $or 性能比较
MongoDB docs have the answer: "When using $or with <expressions> that are equality chec ...
- QT5 QT4--LNK2019 无法解析的外部符号
新创建的工程 #include <QtWidgets/QApplication> #include <QtWidgets/QWidget> #include <QtWid ...
- 强化学习---TRPO/DPPO/PPO/PPO2
时间线: OpenAI 发表的 Trust Region Policy Optimization, Google DeepMind 看过 OpenAI 关于 TRPO后, 2017年7月7号,抢在 O ...
- html5-移动端布局模板
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- D. Duff in Beach
题意 数字串a[0---n-1], 通过不断的重复组成了 b[0,---l-1]l<10^18, 让你计算出 长度小于等于k的最长非递减子序列,满足,取得第 i 个取得是 L1 第i+1个取得 ...
- materials
http://interactivepython.org/runestone/static/pythonds/index.html https://blog.michaelyin.info/scrap ...
- 20155228 实验三 敏捷开发与XP实践
20155228 实验三 敏捷开发与XP实践 实验内容 1. XP基础 2. XP核心实践 3. 相关工具 实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门(新版)>& ...
- Hive静态分区和动态分区
一.静态分区 1.创建分区表 hive (default)> create table order_mulit_partition( > order_number string, > ...
- JustOj 2040: 王胖子买零食 (贪心)
题目描述 大豪哥有个好朋友叫王胖子,众所周知王胖子特别爱吃零食,比如各种不一样的糖果,辣条呀,可是王胖子每个月用在买零食上的钱不是固定的,但是因为王胖子特别爱吃零食,他希望把自己能花在买吃的钱全部用掉 ...