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 ...
随机推荐
- PHP socket通信之UDP
服务端: //服务器信息 $server = 'udp://127.0.0.1:9998'; //消息结束符号 $msg_eof = "\n"; $socket = stream_ ...
- c++ 常用的数据结构
set // constructing sets #include <iostream> #include <set> void checkin(std::set<int ...
- 将n的k位s置1
实例四:将n的k位s置1 方法:result =n|(1<<k) 只使k位变为1,其他位为0,再进行或操作,1与任何数的或操作都是1. 解释: 原数 0000 1011 ---11 数值1 ...
- html5-文件的基本格式
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- RSA解密解密
#!/usr/bin/env python # -*- coding:utf-8 -*- import rsa import base64 # ######### 1. 生成公钥私钥 ######## ...
- arm cortex-m0plus源码学习(三)GPIO
概述: Cortex-m0的integration_kit提供三个GPIO接口,其中GPIO0传输到外部供用户使用,为EXTGPIO:GPIO1是内核自己的信号,不能乱改,会崩掉:GPIO2是一些中断 ...
- brctl 命令详解
安装网桥管理工具包:bridge-utile ```# yum install bridge-utils -y``` ```使用brctl命令创建网桥br1```# brctl addbr br1`` ...
- Ubuntu下sublime-text3安装步骤
1.在Ubuntu中按CTRL+ALT+T打开命令窗口,按下面步骤和命令进行安装即可: 添加sublime text 3的仓库: sudo add-apt-repository ppa:webupd8 ...
- 写出优质Java代码的4个技巧
我们平时的编程任务不外乎就是将相同的技术套件应用到不同的项目中去,对于大多数情况来说,这些技术都是可以满足目标的.然而,有的项目可能需要用到一些特别的技术,因此工程师们得深入研究,去寻找那些最简单但最 ...
- c--socket通信TCP篇
https://www.cnblogs.com/ashen/p/4474360.html #include <sys/socket.h> 2 #include <stdlib.h&g ...