上一页 1 ··· 4 5 6 7 8 9 下一页
摘要: 本来就是自己负责图论,结果水了= = 题目其实很裸,就是求桥的数量,只是要新加上一条边罢了。做法:先缩点、再在树上搜最长链(第一场多校的hdu 4607Park Visit就考了最长链,小样,套个马甲以为就认不出你了),加边后求桥数就可以了。 犯了一大三小四个错误-_- 竟然真的去套模板求桥数了。。竟然没注意到树边都是桥,用树边减链边就可以了。 然后,重新建图的Build()把n传进去了。 再然后,发现读数据从0~m-1,Build()里竟然是1~m。 再再然后,原来存边的su[],sv[]数组开成了 MAXN。 1 #pragma comment(linker, "/ST... 阅读全文
posted @ 2013-07-29 20:32 Thousand Sunny 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 从后向前对已搜点做两遍LIS(最长不下降子序列),分别求出已搜点的最长递增、递减子序列长度。这样一直搜到第一个点,就得到了整个序列的最长递增、递减子序列的长度,即最长递减子序列在前,最长递增子序列在后,得到题目所求的双端队列的最长不下降子序列。注意要去重,当发生替换之后,同种元素在两个序列中的数量不同。为得到最长序列,当然是把少的去掉,留下多的。52 1 2 2 3 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int MAXN=111111; 8 9 vectorv1;10 vec.. 阅读全文
posted @ 2013-07-28 14:03 Thousand Sunny 阅读(513) 评论(0) 推荐(0) 编辑
摘要: 求树上最长链:两遍搜索。第一次从树上任意点开始,最远点必然是某一条最长链上的端点u。第二次从u开始,最远点即该最长链的另一端点。先在最长链上走,不足再去走支链。把询问数m错打成n,狠狠wa了一次= = 1 #include 2 #include 3 4 const int MAXN=111111; 5 6 struct E{ 7 int v,next; 8 }e[MAXN=w)78 printf("%d\n",w-1);79 else80 printf("%d\n",(q[n-1].c-1)+(... 阅读全文
posted @ 2013-07-28 10:34 Thousand Sunny 阅读(296) 评论(0) 推荐(0) 编辑
摘要: 比较裸的FFT(快速傅里叶变换),也是为了这道题而去学的,厚的白书上有简单提到,不过还是推荐看算法导论,讲的很详细。代码的话是照着别人敲的,推荐:http://www.cnblogs.com/kuangbin/archive/2013/07/24/3210565.html写的很详细。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 #define LL __int64 7 8 const double PI=acos(-1.0); 9 10 struct complex{ /... 阅读全文
posted @ 2013-07-28 09:25 Thousand Sunny 阅读(269) 评论(0) 推荐(0) 编辑
摘要: 注意:横向纵向交叉时,只要两条边不是正中的边(当n&1!=1),就可以余下两个chip。代码里数组a[][]第二维下标 0表示横向边,1表示纵向边。 1 #include 2 #include 3 4 int a[1111][2]; 5 6 int main() 7 { 8 int n,m,i,j,x,y; 9 scanf("%d%d",&n,&m);10 for(i=2;i0)26 s++;27 }28 printf("%d\n",s);29 return 0;30 }View Code 阅读全文
posted @ 2013-07-27 21:02 Thousand Sunny 阅读(273) 评论(0) 推荐(0) 编辑
摘要: 题意:保证不能正好配齐n,要求输出可以用的最大硬币数。注意如果用到某种硬币,那么这种硬币就有无穷多个。所以11=3+3+3+3,12=9+9,13=3+3+3+3+3 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 #define LL __int64 9 10 int main()11 {12 LL n,tot=3;13 scanf("%I64d",&n);14 while(1)15 {16 if(n%tot){17 ... 阅读全文
posted @ 2013-07-27 20:56 Thousand Sunny 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 题意难懂,其实就是x1#include#include#include#includeusing namespace std;#define LL __int64int a[10][2],b[5],c[5];int main(){ int n,i,j,tot; memset(b,-1,sizeof(b)); memset(c,-1,sizeof(c)); for(i=0;ix2) swap(x1,x2); if(x1>x3) swap(x1,x3); if(x2>x3) swa... 阅读全文
posted @ 2013-07-27 20:49 Thousand Sunny 阅读(377) 评论(0) 推荐(0) 编辑
摘要: 忘了是偶数了,在纸上画奇数画了半天。。。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 #define LL __int64 9 10 int vis[11111];11 12 int main()13 {14 int n,i,j,tot;15 scanf("%d",&n);16 j=1;17 for(i=0;i=n/2)26 break;27 }28 printf("\n");2... 阅读全文
posted @ 2013-07-27 20:45 Thousand Sunny 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 暴力枚举,注意处理好进位貌似输入的前导零也会被输出,表示做的时候没想到 1 #include 2 #include 3 4 char str[111111]; 5 6 int main() 7 { 8 int T,i; 9 scanf("%d",&T);10 while(T--)11 {12 scanf("%s",str);13 int len=strlen(str);14 int s=0;15 strrev(str);16 while(1)17 {18 ... 阅读全文
posted @ 2013-07-27 12:34 Thousand Sunny 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 推公式+快速幂公式有很多形式,可以写矩阵1、前n-1项和的两倍+2的(n-2)次方,这个写不出啥2、递推式:f(n)=2*f(n-1)+2的(n-3)次方3、公式:2的(n-k-2)次方*(n-k+1)+2的(n-k-1)代码什么的看他的吧http://blog.csdn.net/liuledidai/article/details/9449301第一次写矩阵就不献丑了 1 #include 2 3 const int mod=1e9+7; 4 5 #define LL __int64 6 7 LL p[2][2]; 8 LL q[1][2]; 9 10 LL bb(LL a,LL b,... 阅读全文
posted @ 2013-07-27 11:39 Thousand Sunny 阅读(228) 评论(1) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 下一页