- 博客(12)
- 资源 (1)
- 收藏
- 关注
原创 [POJ 1289] The Cat in the Hat · 数学
大概就是给你两个数A和B,有且仅有一组n,k满足:然后输出 和 #include #include #include #include using namespace std;#define ll long longll A,B,n,k,sq,x,y,ans1,ans2;ll sqr( ll t , ll k ) { ll p = 1 ; while
2015-05-22 08:10:15 655
原创 [POJ 1195] Mobile phones · 树状数组
二维树状数组模板,不过注意要用读入优化。#include #include #include using namespace std;#define lowbit( x ) (( x ) & ( -x ))const int N = 1025 ;int n,f[N][N],x1,y1,x2,y2,c,p;void edit( int x , int y , int c ) {
2015-05-22 07:54:58 439
原创 [POJ 2014] Flow Layout · 模拟
随便挑的条题目,模拟水题。(丢代码跑)#include #include #include #include using namespace std;int n,x,y,ansx,ansy,nowx,nowy,nexty;int main(){ cin >> n ; while ( n ) { ansx = ansy = nowx = nowy = nexty =
2015-05-21 10:22:27 596
原创 [POJ 2182] Lost Cows · 树状数组
着手准备pku夏令营所以得把英文题好好刷一刷。写树状数组只是觉得比较好写一开始机房里的小伙伴想到了逆推的方法,但没有想出来怎么确定值,然后发现可以用树状数组来搞。从后往前搞,第i个位置上原本的值是ans[i],那么之前比ans[i]小的数就是a[i] ,之后比ans[i]小的数就是sum(ans[i]),所以ans[i] = a[i] + sum( ans[i] ) + 1 ,其中a[
2015-05-20 21:20:15 403
原创 [Vijos 1083] 小白逛公园 · 线段树
总体为带单点修改的查询区间最大连续子段和。对每个区间维护四个值: left_max , right_max , sum , ans .分别是区间的最大前缀和,最大后缀和,区间总和,以及最大连续子段和(也就是要求的值)。对于当前区间father[l,r] ,下属的两个区间分别为son1,son2,father的left_max等于 max (son1.left_max , son1.sum
2015-05-20 11:36:53 867 2
原创 [POJ 1469]COURSES · 二分图
借着这道模板题学了下二分图(orz蒟蒻)。题目大意是有p个课程和n个学生,每门课程会有k个学生愿意选择,但每个学生只能选择一门课程,问你能否使每门课程有且仅有一名学生。先讲一下二分图匹配:关于二分图
2015-05-14 09:42:48 494
原创 [BZOJ 1034] ZJOI 2008 泡泡堂BNB · 贪心
排序以后贪心,每次最强的比较能赢就赢,最弱的能赢就赢,否则就用最弱的去浪掉对面最强的。最少得分可以用总分减去对方最多得分。没了。#include #include #include #include using namespace std;const int N=100005;int n,a[N],b[N];int work(int a[],int b[]){ int
2015-05-05 23:14:55 588
原创 [BZOJ 2456] mode · 模拟
我最近真的没有在刷水题好吧这题应该算是智商题了。。。抵消思想:每两个不同的数互相抵消,因为众数出现了至少n/2次,所以剩下的就是众数。没了。#include using namespace std;int n,x,cnt,ans;int main(){ scanf("%d",&n); cnt=0;ans=0x7fffff; while (n--){ scan
2015-05-04 22:47:33 440
原创 [BZOJ 1260] CQOI 2007 涂色paint · 动态规划
f[i][j]表示i到j的最少染色次数,然后就是细节处理。#include #include #include #include using namespace std;char st[55];int n,f[55][55];int main(){ cin>>st+1;n=strlen(st+1); memset(f,10,sizeof f); for (int i=1
2015-05-03 23:05:45 625
原创 [BZOJ 1045] HAOI 2008 糖果传递 & [BZOJ 3293] CQOI 2011 分金币 · 数学
这个是原题解,笔者修改了一些地方,更好懂一点。中位数。我们令xi为第i-1个人给i的金币数(如果小于0就是i给i-1金币)。那么每个人最后的金币数可以用方程表示为:a1 + x1 - x2 = pa2 + x2 - x3 = p......an-1 + xn-1 - xn = pan + xn - x1 = p化简为:x2
2015-05-02 09:39:48 741
原创 [BZOJ 1088] SCOI 2005 扫雷Mine · 暴力
一开始还想了一段特别宏大的DP方程。。。后来发现了又犯蠢了每个第一行的格子最多管第二行3个格子,所以只要确定前两个格子,第三个也可以确定,然后就枚举第一个格子然后判断,就这么水过去了。。。#include #include #include using namespace std;const int N=10005;int n,a[N],ans,f[N];bool check(
2015-05-01 20:30:27 500
原创 [BZOJ 2326] HNOI 2011 数学作业 · 矩阵乘法
对于k位数,我们设计一个矩阵:初始矩阵 [ 0 0 1 ]然后就是分段矩乘,0~9,10~99,100~999,......(没必要用快速乘,因为肯定不会爆long long)#include #include #include #include using namespace std;#define ll long longll n,m,t;struct
2015-05-01 08:38:22 396
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人