随笔分类 -  算法--套题总结

摘要:SGU 7/15 & 7/17http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26430#overviewCF 7/16http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26433#overview 阅读全文
posted @ 2013-07-17 18:46 yefeng1627 阅读(238) 评论(0) 推荐(0)
摘要:水平太渣. 唯有看完解题报告+标程 AK这套题.A CircleGame. 需要取上整,核心点加上了一个小于1的小数.当n = 2时,有 , 然后可以验证下当n取其他值时也满足。所以就有又 , 则其特征方程的两个解为:当 n = 2. 时, 其特征方程为:化简得到:因为所以有:S_2 - 2*a*S_1 + (a^2+b) = 0得到线性递推关系, 然后矩阵快速幂随便搞搞就好了。// Sn = ceil( [a + sqrt(b)]^n ) % m;#include<cstdio>#include<cstdlib>#include<cstring>#incl 阅读全文
posted @ 2013-06-05 22:52 yefeng1627 阅读(491) 评论(0) 推荐(0)
摘要:先腾个地.有时间再写. 阅读全文
posted @ 2013-05-29 19:33 yefeng1627 阅读(109) 评论(0) 推荐(0)
摘要:做了前两场虽然有点恶心,但也没今天那么想吐嘈.... 反正是一题未A..不得不承认依旧很菜..A题,死了命的提示结果错误.... 显然已模拟题.封装 remove 与 maintain 然后print.. 各种情况都考虑,将其后台数据都输出比较.还是未找到错误点在哪里..#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;const int N = 50;char mp[N][N];int n, m;bool vis[N] 阅读全文
posted @ 2013-05-22 23:03 yefeng1627 阅读(241) 评论(0) 推荐(0)
摘要:题目来源: 2012天津现场赛A, 背景为麻将的模拟题,按照要求模拟就好。B,sqrt(N)分解因子,然后暴力算即可#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<algorithm>using namespace std;int sum(int x,int b){ int res = 0; while(x){ res += (x%b)*(x%b); x /= b; } return res;}char mp[50] = " 阅读全文
posted @ 2013-05-22 12:13 yefeng1627 阅读(205) 评论(0) 推荐(0)
摘要:hdu 4548 美素数 用线性筛法筛选出10^6的素数,然后预处理统计下.. O(1)就能得到结果了.#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;const int N = (int)1e6+10;bool vis[N];int p[N], sum[N];void GetPrime(){ memset(vis,0,sizeof(0)); vis[1] = 1; int cnt = 0; for(int i = 2 阅读全文
posted @ 2013-05-19 16:31 yefeng1627 阅读(225) 评论(0) 推荐(0)
摘要:弱到一定程度了... 不过还好.又涨经值和姿势了.....hdu 4551 生日猜猜猜 月份和日期都比较小, (12,31) 果断暴力, 然后判定下当前月份和天数是否合法.#include<cstdio>#include<cstdlib>#include<cstring>using namespace std;int day[2][13] = { {0,31,28,31,30,31,30,31,31,30,31,30,31 } ,{0,31,29,31,30,31,30,31,31,30,31,30,31 }};int gcd(int a,int b){ r 阅读全文
posted @ 2013-05-19 14:34 yefeng1627 阅读(210) 评论(0) 推荐(0)
摘要:训练赛链接:http://openoj.awaysoft.com:8080/judge/contest/view.action?cid=424#overview题目来源:The 10th Zhejiang Provincial Collegiate Programming Contest还是想吐嘈 ZOJ的题目描述,与模拟题的恶心程度........AApplications 背景是ACM集训队选拔,根据OJ题数,区域赛获奖,CF/TC排名, 还有个性别, 注意的地方是CF不满三场不计算.#include<cstdio>#include<cstring>#include 阅读全文
posted @ 2013-05-18 17:13 yefeng1627 阅读(585) 评论(2) 推荐(0)
摘要:全文资料来自wiki:http://en.wikipedia.org/wiki/Cyclic_numberCyclic numberCyclic Number 是一个整数是,且其连续的倍数 (1,2,..,L-1) ,是其本身数字的一个循环。 常见的如下142857 × 1 = 142857142857 × 2 = 285714142857 × 3 = 428571142857 × 4 = 571428142857 × 5 = 714285142857 × 6 = 857142而形如下非连续的倍数不是076923 × 1 = 阅读全文
posted @ 2013-05-14 10:56 yefeng1627 阅读(330) 评论(0) 推荐(0)
摘要:还是很弱啊,发现确实要多做CF, 不单单训练思维,而且还有代码。还能多参考大神的思路与代码。Div 2.A题, 给定 n <= 5000, 求满足 1<=a<=b<=c<=n, 的直角三角形数量.解法, 数据量不大,可以暴力枚举 a, b, 然后求满足的 cView Code #include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>typedef long long LL;const int N = 10000;int main(){// me 阅读全文
posted @ 2013-05-13 12:58 yefeng1627 阅读(194) 评论(0) 推荐(0)
摘要:感谢 谢大,duoxida,zhsl ,教会了我几个训练赛当中没有想出来的题。A Force Brute题意: 没发现其水题本质啊.. 给定 N个单词, 然后问最大循环次数.解法: KMP next数组的运用, 更详细的可以看这一篇总结http://www.cnblogs.com/yefeng1627/archive/2013/04/28/3050027.html这里就简要说下, 因为求next的过程是一个一个构造循环节的, (L+1)-next[L+1] 即为当前字符串的最小循环节长度, 而 L%( (L+1)-next[L+1] ) 表示目前 循环节构造了多少个,若为0则意味着构造满了.. 阅读全文
posted @ 2013-05-12 20:38 yefeng1627 阅读(314) 评论(0) 推荐(0)
摘要:A Alice and Bob解法一, 比赛时用的解法是,因为N<=10000,那么枚举A,B分别拿的时候数量,然后求最小,然后得出A,B拿的最小次数的上下界比较,得出区间的几个关系,因为k1>=k2,判定有点复杂。特殊情况比较多。解法二,是用动态规划,状态方程 dp( i, j ) , 表示剩下 i 块石头,j = 0时,最后一次是A拿最小次数, j = 1,最后一次是B拿最小次数。转移方程为 dp( i, 0 ) = min{ dp(i-2^k,1) } +1, dp( i, 1 ) = min{ dp(i-3^k, 0) } +1 .比较下还是解法二比较好,没那么多特殊情况判 阅读全文
posted @ 2013-05-12 19:34 yefeng1627 阅读(293) 评论(0) 推荐(0)
摘要:题目来源 The 13th Zhejiang University Programming Contest链接:http://openoj.awaysoft.com:8080/judge/contest/view.action?cid=421#overviewA -Alien's Organ题意: 事件出现平均概率为a, 问出现次数小于等于N的概率解法: 泊松分布,,跟着公式算就好.View Code // p(k) = e^(-ave) * ave^k / k!#include<cstdio>#include<cmath>int main(){ double 阅读全文
posted @ 2013-05-09 13:40 yefeng1627 阅读(202) 评论(0) 推荐(0)
摘要:训练赛链接:http://www.acmore.net/contest.php?cid=1013Problem A: Yard题意: n*m的格子,有树与空地,要求每个位置上下左右树的数量为偶数.求拔除与种植最小花费.解法: 状态压缩, 第一行状态确定后,则所有行都确定. 然后枚举第一行状态,取个最小值即可.View Code #include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std; const int inf = 0x3f3 阅读全文
posted @ 2013-05-09 13:21 yefeng1627 阅读(413) 评论(0) 推荐(0)
摘要:A: 相邻三个和最大,及对应中间位置. 暴力即可.View Code #include <iostream>#include <cmath>#include <cstring>#include <cstdio>#include <string>#include <stdlib.h>#include <algorithm>using namespace std;typedef long long LL;const LL Mod= 1e9+7;const int N = 1010;int a[N], n; int 阅读全文
posted @ 2013-05-06 10:21 yefeng1627 阅读(467) 评论(0) 推荐(0)
摘要:A 题: 越来越弱,都掉渣了....连暴力递归模拟都不会写了...对每个黑棋递归搜索其边界,若遇到相同的黑棋则数量+1继续找,遇到0或者边界则直接return.View Code #include<cstdio>#include<cstdlib>#include<cstring>char mp[110][110];bool flag;int n, m, dir[4][2] = {0,1,0,-1,1,0,-1,0};bool legal(int x,int y){ if( x>=0&&x<n&&y>=0&am 阅读全文
posted @ 2013-04-30 21:24 yefeng1627 阅读(227) 评论(0) 推荐(0)
摘要:解题报告转摘自其它博客。最好看这里http://acmicpc.info/archives/1229A 这题非常简单,全场所有队都过了。B此题只需要枚举每个盒子还剩了几个糖,算出其概率就可以了,不过需要推一会儿公式。 i = 0,1,...,nC 分两部分处理。首先计算出周长为L的本质不同三角形个数,可以O(n)递推;而后对于原问题可以直接枚举n的约数来处理。源代码主干如下: for(int i=1; i<ran; i++)a[i]=add(a[i-2],i/3-i/4);for(int i=1; i<ran; i++)for(int j=i+i; j<ran; j+=i)a 阅读全文
posted @ 2013-04-23 22:57 yefeng1627 阅读(292) 评论(0) 推荐(0)
摘要:hdu 2131View Code#include<stdio.h>#include<string.h>int main(){ char ch[2],s[210]; while(scanf("%s %s",ch,s)!=EOF) { char x = ch[0]; int len = strlen(s); int cnt = 0; if( x >= 'A' && x <= 'Z' ) { for(int i = 0; i < len; ++i ) ... 阅读全文
posted @ 2013-04-16 10:19 yefeng1627 阅读(180) 评论(0) 推荐(0)
摘要:对于序列 a_1,a_2,..a_i.,a_n从小到大排列处理花费会最小。一个一个处理完,例如当处理 a_1 则此时花费分为 a_1, 以及 a_x (x>1)的花费来计算 1. a_1 时 2. a_x 时 当消除掉 a_1 后,又生成一个新的 序列 a_1`, a_2`, ..., a_n` 此时可以知道, a_i` = a_i - a_1 + 1 我们可以通过 线段树来 维护更新序列,这样省事. 但是这题 n = 1e5 , 且极限T = 100, 此时时间复杂度达到 1e7,若再添加个 log(N) 复杂度,就会TLE了。 我们可以发现总花费为 序列除了被... 阅读全文
posted @ 2013-04-14 21:56 yefeng1627 阅读(265) 评论(3) 推荐(0)
摘要:Problem A 一边输入边一边维护残留网络,然后跑ISAP。小数据过了,大数据TLE。据说可以BFS预处理 层次网络。可以过。View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>using namespace std;const int inf = 10000000;const int MAXN = 500;#define MIN(a,b) (a)<(b)?(a):(b)#define MAX(a,b) (a)>(b)?( 阅读全文
posted @ 2013-04-14 21:29 yefeng1627 阅读(280) 评论(0) 推荐(0)

Launch CodeCogs Equation Editor