2013年12月5日

codeforces 111B Petya and Divisors

摘要: 题目:DescriptionLittle Petya loves looking for numbers' divisors. One day Petya came across the following problem:You are givennqueries in the form "xiyi". For each query Petya should count how many divisors of numberxidivide none of the numbersxi - yi, xi - yi + 1, ..., xi - 1. Help him 阅读全文

posted @ 2013-12-05 22:00 uestc小田 阅读(244) 评论(0) 推荐(0) 编辑

2013年12月4日

poj 1185 炮兵阵地 状压dp

摘要: 分析:因为每一行的状态和上两行的状态有关,因此dp[i][r][p]代表第i行状态为state[r]以及第i-1行为state[p]时的最大炮台数目;状态是有限的,可以dfs出来代码:#include#include#include#include#include#include#include#include//#define DEBUG //todousing namespace std; int nn;int ans;int m,n,cnt,bin[11],dp[110][110][110],state[100],t,gra[110],_cnt,sum[110];char c;v... 阅读全文

posted @ 2013-12-04 14:16 uestc小田 阅读(156) 评论(0) 推荐(0) 编辑

2013年12月1日

cf #216 C - Valera and Elections

摘要: 题目大意:给你一棵树,节点间的边有的有标记1,有的有标记2,问你至少选取哪几个节点使得这些节点到节点1的路径中包含了所有的标记为2的边;思路:统计每个节点下与标记为2的边相邻的节点的数目,选取的节点即为数目为1的节点编号;代码:#include#include#include#include#include#include#include#include//#define DEBUG //todousing namespace std; int nn;struct node{ int to; node *next;}*head[110000],*tail[110000];i... 阅读全文

posted @ 2013-12-01 15:37 uestc小田 阅读(230) 评论(0) 推荐(0) 编辑

2013年11月27日

cdoj1365 木杆上的蚂蚁

摘要: Description在一根细木杆上,有一些速度相同蚂蚁,它们有的往左走,有的往右走,木杆很细,只允许一只蚂蚁通过,所以当两只蚂蚁碰头的时候,它们会掉头继续前进,直到走出边界,掉下木杆。已知木杆的长度和每只蚂蚁的名字、位置和初始方向,问依次掉下木杆的蚂蚁花费的时间以及它的名字。分析:对于杆上的蚂蚁,当两个蚂蚁碰头后,它们互换方向,但是我们仍然可以看成它们的方向没有改变,只是一只蚂蚁的路程让另外一只来走而已,所以对于每一只蚂蚁,如果不区分它们,那么它们的时间是可以求出来的,即它们所在的位置到终点的位移。由于每一只蚂蚁的相对位置没有改变,因此根据时间的先后和对应那只蚂蚁的方向,我们就知道了每只蚂蚁 阅读全文

posted @ 2013-11-27 20:02 uestc小田 阅读(1310) 评论(0) 推荐(1) 编辑

2013年11月25日

cf #214 Dima and Salad

摘要: 题目:分析:将b[i]*k,那么就可以得到,Σ(a[i]-b[i])=0,为了使Σa[i]最大化,可以将之转化为一个容量为0的背包问题,dp解决,dp[i][j]表示放第i件物品时容量为j时的最大值;代码:#include#include#include#include#include#include#include#define DEBUG //todousing namespace std; int nn;int n,k,a[110],b[110],rem[110],con[110],dp[110][20010],ans;void ini(){ ans=-1; cin>... 阅读全文

posted @ 2013-11-25 14:52 uestc小田 阅读(219) 评论(0) 推荐(0) 编辑

2013年11月21日

cf #213 Matrix

摘要: 题目:http://codeforces.com/contest/365/problem/C题目分析:sum(x,y,z,t)=s(x,y)*s(z,t),s(x,y)=s[x]+s[x+1]+...+s[y].由于strlen(s)#include #include #include #include #include #include using namespace std;long long eq,sum[5000],slen,f[46100],ssum,ans;char s[5000];void ini();void work();int main(){ ini(); wo... 阅读全文

posted @ 2013-11-21 22:22 uestc小田 阅读(209) 评论(0) 推荐(0) 编辑

2013年11月7日

hdu 2222 Keywords Search(AC自动机入门题)

摘要: 初学ac自动机。还要努力。参考了许多代码,仿佛是拷贝的一样了。。。。// hdu Aho-Corasick automation.cpp : 定义控制台应用程序的入口点。//#include #include #include #include #include #include #include using namespace std;int n;char str[1100000];int ans;struct node{ int f; node *fail,*next[26]; node() { f=false; fail=NULL; ... 阅读全文

posted @ 2013-11-07 17:28 uestc小田 阅读(196) 评论(0) 推荐(0) 编辑

2013年10月16日

算法复习之::LCS最长公共子序列

摘要: 算法思想:dp[i][j]记录到A[i],B[j]的位置是Lcs的最大长度, 转移方程:I:dp[i][j]=max(dp[i-1][j],dp[i][j]) (i>1) II:dp[i][j]=max(dp[i][j-1],dp[i][j]) (j>1) III:dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1) (A[i]==A[j],i>1,j>1) 处理完后,再从dp[A.length][B.length]处开始回溯找出最大子序列。代码: #include #include #include #include #in... 阅读全文

posted @ 2013-10-16 15:44 uestc小田 阅读(136) 评论(0) 推荐(0) 编辑

纪念一下::AstronomicalRecordsEasy

摘要: #include #include #include #include using namespace std;class AstronomicalRecordsEasy{ public: int minimalPlanets(vector A, vector B) { int a=A.size(),b=B.size(),ans=a+b,dp[60][60]; for(int i=0;i0) dp[k][l]=max(dp[k][l],dp[k-1][l]); if(... 阅读全文

posted @ 2013-10-16 02:24 uestc小田 阅读(128) 评论(0) 推荐(0) 编辑

2013年10月15日

codeforces 1B Spreadsheets 解题报告

摘要: 题目大意: 用26个大写字母A~Z代表1~26,例如A是1,B是2,Z是26,AA是27; 由于没有代表0的字母,因此就有例如AAAA!=0.5*BAAA;因为AAAA=26^3+26^2+26+1,而BAAA=2*26^3+26^2+26+1; 因此先求出n的位数m,然后构造出AA..A(m个A),然后在每个位置上取最大值。代码:#include #include #include #include #include using namespace std;int n;char s[20];char ans[20];int sum[20],f[20];void convert(in... 阅读全文

posted @ 2013-10-15 12:30 uestc小田 阅读(289) 评论(0) 推荐(0) 编辑

导航