- 博客(152)
- 收藏
- 关注
原创 Light Oj 1284 Lights inside 3D Grid(概率期望)
题意:X*Y*Z。每个位置(x,y,z)有一盏灯,初始时是灭的。K轮操作。每轮任意选两盏灯(可以相同)将其之间的所有灯翻转。问最后明着的灯的数量期望。 思路:先求出每盏灯在一轮中被改变的概率,对于(i,j,k)位置的,只要选择的两盏灯不在同一侧就行。那么可以对于每一维分别算,比如对于X这一维,就是减去在其同侧的。然后计算K轮被改变奇数次的概率就是该盏灯最后对答案的贡献。这f(n)表示n次改变
2016-04-30 16:42:49 564
原创 CodeForces 580D Kefa and Dishes(DP)
题意:有n种食物,每种食物有一个愉悦度,现在要从中选择m个食物,使得愉悦度最大,特别的,有K种规则,规定连吃两种食物有愉悦度加成,现在想要求出最大可能的愉悦度。 思路:看数据范围显然要状态压缩,dp[1 #include using namespace std; #define LL long long LL n,m,r,a[20],dp[1<<18][20],rul[
2016-04-30 11:52:53 443
原创 CodeForces 580C Kefa and Park(DFS)
题意:给你一棵树,然后每个叶子节点会有一家餐馆,你讨厌猫,就不会走有连续超过m个节点有猫的路,然后问你最多去几家饭店 思路:直接DFS #include using namespace std; const int maxn = 1e5+6; int flag[maxn]; vectore[maxn]; int n,m,ans=0; void dfs(int u,int num,int
2016-04-30 11:33:20 789
原创 CodeForces 580B Kefa and Company
思路:滑窗一波 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define fuck printf("fuck") #define FIN freopen("input.txt","
2016-04-30 11:31:43 394
原创 CodeForces 580A Kefa and First Steps
题意:求最长不递减子序列 思路:直接扫一遍就好了... #include using namespace std; const int maxn = 1e5+6; int ans = 0; int a[maxn]; int anss = 0; int main() { int n; scanf("%d",&n); for (int i = 1;i<=n;i++)
2016-04-30 11:30:24 743
原创 CodeForces 567D One-Dimensional Battle Ships
题意:有一个一维线段,上面摆了k个船,每个船的长度都为a,然后有一个人来打,问你第几次攻击 就可以使得这个船无论怎么摆都不合法了 思路:一个区间合并的题,对于每一次的攻击,都只会影响到这个点所在区间,然后我们更新一下新出现的两个区间里面能摆多少个船就好了 #include using namespace std; sets; mapvis; int main() { int n
2016-04-30 00:10:46 297
原创 BZOJ 4443 小凸玩矩阵
题意:中文题 思路:二分答案,然后比较显然的网络流建图之后看看最大流是否大于n-k+1就可以了 #include using namespace std; #define INF 1e9+100 const int maxn = 250*250+100; struct Edge { int from,to,cap,flow; Edge(int u,int v,int c,int f
2016-04-29 20:35:35 338
原创 CodeForces 567C Geometric Progression
题意:从一个长度为n的序列中,选出3个数,要求l1 思路:开两个map分别维护这个数前面和后面的每类数的个数,然后瞎搞搞 #include using namespace std; const int maxn = 200000+100; #define LL long long mapmark1; mapmark2; LL a[maxn]; int main() { int
2016-04-29 20:33:37 668
原创 CodeForces 567B Berland National Library
思路:按照题意模拟就好了 #include using namespace std; mapmark; int main() { int n; scanf("%d",&n); int now=0,tip=0,ans=0; for (int i = 0;i<n;i++) { string s; cin >> s; int k; scanf(
2016-04-29 20:31:57 385
原创 CodeForces 567A Lineland Mail
思路:水题 #include using namespace std; const int maxn = 1e6+10; #define LL long long #define INF 0x3f3f3f3f3f3f3f3fLL LL a[maxn]; int main() { int n; scanf("%d",&n); for (int i = 1;i<=n;i++)
2016-04-29 20:30:00 510
原创 CodeForces 668C Little Artem and Random Variable(数学)
题意:有两个骰子,每个骰子有n面,现在你需要求每个骰子扔到每一面的概率是多少,现在给你扔到min(a,b)=i的概率和max(a,b)=i的概率。 思路:由题意知道P(max(a,b))=i P(min(a,b))=i 那么显然可以推导出来 P(max(a,b) P(min(a,b)>=i) = P(a>=i)*P(b>=i) = (1-P(a 上面那个式
2016-04-29 15:46:30 517
原创 BZOJ 3504: [Cqoi2014]危桥 最大流
题意:中文题 思路:网络流,正常建边之后跑一遍网络流,但是这样可能会使得a1到an的流量跑到b1到bn去了,所以把b换过来,然后再跑一发网络流就好了 #include using namespace std; #define INF 1e9 const int maxn = 2550; struct Edge { int from,to,cap,flow; Edge(int u,
2016-04-28 18:38:38 292
原创 CodeForces 10D(DP)
题意:求最长公共上升子序列 思路:找了个模板..然后就.... #include using namespace std; const int maxn = 505; int n1,n2; int ans,cnt; int a[maxn],b[maxn]; int dp[maxn][maxn]; int pre[maxn][maxn]; int lcis[maxn]; void get
2016-04-28 18:36:58 769
原创 CodeForces 10B Cinema Cashier
题意:有一个电影院,是k*k的,然后有n波人依次到来,每一波人都想选择尽量靠中间的位置,就是这一波人都必须坐在同一行,并且有一个花费就是abs(x-zx)+abs(y-zy),然后你需要给他们安排座位,使得花费最小,如果花费一样,就坐左前方。问你怎么去安排 思路:暴力即可 #include using namespace std; #define INF 1e9 int n,k,x;
2016-04-28 18:35:55 1077 2
原创 CodeForces 10A Power Consumption Calculation
思路:水题 #include using namespace std; #define LL long long const int maxn = 105; int n,p1,p2,p3,t1,t2; struct Node { int s; int t; }nodes[maxn]; int vis[3000]; int main() { scanf("%d%d%d%d%d%
2016-04-28 18:34:45 441
原创 HDU 5242 Game
题意:一棵树有n个结点,n-1条边,每个结点有个权值。每次可以获得从根节点走到叶子结点所有结点的权值和,但是每个结点的权值只能使用一次。求走k次所能获得的最大权值和 思路:首先dfs一次求出所有叶子结点到根结点的权值和,然后从大到小排序,然后根据这个顺序再一次dfs求出每个结点到根节点的权值和,然后再次排序选前k个,证明:每次选择一个叶子结点走到根节点,相当于每次取一条单链,对于有交叉的两条链,
2016-04-27 21:01:54 293
原创 CodeForces 669D Little Artem and Dance
题意:给你n个数,一开始是1 2 3 4 5 6 这样的,现在有两个操作,第一个操作是所有数向右边移动x个位置,第二个操作奇数和偶数的位置互换 思路:比较显然就是,奇数和偶数位置的数的相对位置是不会变的,那么我们只要知道1和2这两个位置的数是啥就好了 然后交换的时候,我们就模拟一下这两个位置的交换就好了 #include using namespace std; int n,q; i
2016-04-27 19:40:52 640
原创 CodeForces 669E Little Artem and Time Machine(树状数组)
题意:有三个操作 1 x y,在第x秒插入一个y 2 x y,在第x秒移走一个y 3 x y, 问第x秒有多少个y 思路:听说是可持久化Treap...不过好像无脑树状数组也行 #include using namespace std; const int maxn = 1e6+1; mapc[maxn]; mapvis; int tot = 0; int
2016-04-27 16:08:19 730
原创 CodeForces 669C Little Artem and Matrix(暴力)
题意:给你一个矩阵,这个矩阵有三个操作 1.将矩阵的第x行向左边旋转一位 2.将矩阵的第y列向上边旋转一位 3.现在的第x,y位置是z 问你最初的矩阵长什么样子 思路:显然倒着做然后暴力就好了 #include using namespace std; const int maxn = 105;
2016-04-27 16:03:27 871
原创 CodeForces 669B Little Artem and Grasshopper
题意:有格子是1*n这么大的,每个格子里面都写着一个箭头,表示这个人要往哪儿去跳,并且给你这个人跳跃的距离是多少,然后问你这个人会不会一直跳下去…… 思路:开个数组标记下就可以了 #include using namespace std; const int maxn = 1e6+10; string s; int vis[maxn],n,now,jump[maxn]; int mai
2016-04-27 16:02:03 573
原创 CodeForces 669A Little Artem and Presents
题意:同学有n个糖果,然后每一次可以给人任意个糖果,但是给出去的糖果数量得保证和上一次的数量不一样。问你最多能给多少手 思路:显然是1 2 1 2 1 2这样的... #include using namespace std; int main() { int n; scanf("%d",&n); printf("%d\n",(n/3)*2+((n%3)?1:0))
2016-04-27 16:00:38 529
原创 UVALive 3135 Argus(优先队列)
思路:优先队列 #include using namespace std; struct Item { int QNum,Period,Time; bool operator <(const Item&a)const { return Time > a.Time || (Time == a.Time && QNum > a.QNum); } }; int main() {
2016-04-26 22:44:21 423
原创 HDU 5239 Doom
思路:打个表之后发现最多操作29次,之后区间的值就不会再改变,然后就是一个线段树了 #include using namespace std; #define LL long long #define ULL unsigned long long #define maxn 100005 + 10 #define mod 9223372034707292160ULL #define lso
2016-04-26 22:42:49 565 2
原创 hdu5241 Friends
题意:一个错综复杂的关系 思路:看样例,猜一发规律是32^n,然后上个大整数就可以了,用心体会 /*#include using namespace std; const int base=1e4; void trans(char *x,int *a) //将正序的字符串x转为10^4进制逆序大整数a { int lx=strlen(x); int &la=a[0]=1; f
2016-04-26 15:16:39 681
原创 hdu5245 Joyful
思路:显然考虑正着做会很麻烦,因为矩阵是可以重叠的,那么就设矩阵k次都没被选中的概率为pp,那么最后累加1-pp就是概率了。对于任意一个矩阵,他不被选的概率为(r-1)^2*m^2+(c-1)^2*n^2+(n-r)^2*m^2+(m-c)^2*n^2,注意到四个角会被重复计算一次,那么再减去(r-1)^2*(c-1)^2,(r-1)^2*(m-c)^2,(n-r)^2*(c-1)^2,(n-r)
2016-04-25 22:26:59 416
原创 hdu5236 Article
题意:你要输入一篇n个字的文章,每到i+0.1s时可以输入一个字符,每到i+0.9s时有p的概率会奔溃,回到开头或者上一个存盘点,每到第i秒有一次机会可以选择按x个健存盘或者不存,打印完整篇文章之后必须存盘一次才能算完成,求打完之后的最小期望 思路:令dp[i]为打完i个字符的期望,那么不考虑存盘的情况下有dp[i]=dp[i-1]+p*(1+dp[i])+(1-p),意思是要考虑第i个字符,首
2016-04-25 20:59:24 742
原创 light oj1005 Rooks
思路:先从n行里面选择m行,然后再乘上一个全排列A(n,m)就行了 #include using namespace std; const int inf = 0x3f3f3f3f; #define LL long long LL C[33][33]; int main() { C[0][0] = 1; for (int i = 1; i <= 30; ++i) {
2016-04-23 23:08:34 367
原创 poj1971 Parallelogram Counting
题意:给n个点,问能组成四边形平行四边形的个数(有可能有三点共线) 思路:组成平行四边形的判定条件之中有一个是,对角线互相平分,即中点相同,所以直接n^2算出所有中点然后排序求就好了 #include using namespace std; const int maxn = 1005; struct Node { int x,y; }mid[maxn*maxn],nodes[ma
2016-04-23 22:58:04 537
原创 CodeForces 9D How many trees?
题意:问你一个二叉树,有n个节点,深度大于等于h的一共有多少种,这个二叉树满足左儿子比自己小,右儿子比自己大的特性。 思路:dp[i][j]表示当前用了i个节点,高度小于等于j的方案数 #include using namespace std; #define LL long long LL dp[40][40]; int main() { int n,h; scanf("
2016-04-23 08:54:57 610
原创 CodeForces 9C Hexadecimal's Numbers(DFS)
题意:给你n,问你从1到n有几个数字只由0和1组成 思路:DFS一波 #include using namespace std; map vis; #define LL long long LL ans = 0; int n; void dfs(int x) { if (x>n) return; if (vis[x]) return; vis[x]=1; ans+
2016-04-23 08:40:34 454
原创 CodeForces 9B Running Student
题意:有一个小朋友,考试要迟到了,所以必须尽快的赶到学校。他跑步的速度是v2,公交车的速度是v1,现在他可以选择从某一站下车,然后飞奔过去,现在问你应该从哪一站下车。不允许从第一站下车啦,因为他就是从那儿上车的。 思路:暴力就好了 #include using namespace std; const int maxn = 1005; int a[maxn]; double dis(d
2016-04-23 08:39:12 400
原创 CodeForces 9A Die Roll
题意:有三个人在玩掷骰子,然后第一个人扔了个A,第二个人扔了个B,现在问你有多大的概率能够赢过这两个人,平局也算自己赢。 思路:水题 #include using namespace std; int gcd(int a,int b) { if(b==0)return a; return gcd(b,a%b); } int main() { int a,b;
2016-04-23 08:37:41 594
原创 CodeForces 665E Beautiful Subarrays
题意:问你有多少个区间,异或起来大于等于k 思路:显然求个前缀和之后,就等于有多少对数异或起来大于等于k了,每次暴力爬字典树就好了,当k这一位等于0的时候,我们可以直接加上另外一边1的子树大小,因为爬那边之后,我怎么爬都是大于等于k的 #include using namespace std; const int maxn = 2e7+6; struct Tri { int c
2016-04-23 00:03:46 906
原创 CodeForces 665D Simple Subset
题意:给你n个数,你需要找到一个最大的子集,使得这个子集中的任何两个数加起来都是质数。 思路:建边的话,跑dfs一波最大团 #include using namespace std; const int maxn = 1005; int pri[2000005]; bool flag[maxn], a[maxn][maxn]; int ans, cnt[maxn], group
2016-04-23 00:00:52 401
原创 CodeForces 665C Simple Strings
题意:现在给你一个串,让你使得相邻的字符都不一样,要求修改的字符最少 问你最后的字符串长什么样 思路:贪心,如果这个位置一样,那就变化就好了 #include using namespace std; string s; int main() { cin>>s; s+='a'; for(int i=1;i<s.size()-1;i++) {
2016-04-22 23:58:33 739
原创 CodeForces 665B Shopping
题意:现在有k件商品,每个商品的位置已经告诉你了 现在有n个人,每个人有m个需求,每个需求就是要把第a[i][j]个物品拿到第一个位置来 他的代价是pos[a[i][j]] 问你所有代价是多少 思路:暴力就好 #include using namespace std; const int maxn = 205; int a[maxn],b[maxn],t=0; int main(
2016-04-22 23:57:08 509
原创 CodeForces 665A Buses Between Cities
思路:水题 #include using namespace std; int main() { int a,ta,b,tb; scanf("%d%d%d%d",&a,&ta,&b,&tb); int h,m;scanf("%d:%d",&h,&m); m+=60*h; int ans = 0; for(int i=300;i<24*60;
2016-04-22 23:55:47 386
原创 CodeForces 612D The Union of k-Segments
题意: 给你一堆区间,然后让你把覆盖k次及k次以上的区间都输出出来 思路: 直接暴力扫分界点就好了 分界点是正向覆盖k次的就加进左端点,是反向,就加进右端点,然后输出就好了 #include using namespace std; #define maxn 3000006 pair Line[maxn]; int tot = 1; int t[maxn]; int main(
2016-04-22 23:52:16 504
原创 CodeForces 612C Replace To Make Regular Bracket Sequence
题意: 给你一个只含有括号的字符串,你可以将一种类型的左括号改成另外一种类型,右括号改成另外一种右括号 问你最少修改多少次,才能使得这个字符串匹配,输出次数 思路: 用stack,每次将左括号压进stack里面,遇到右括号就判断一下就好了 非法就很简单,看看栈最后是否还有,看看右括号的时候,左括号的栈是否为空 #include using namespace std; str
2016-04-22 23:49:12 560
原创 CodeForces 612B HDD is Outdated Technology
题意:给你n个数,一开始你在1,然后要走到2,然后走到3,问你最后他走到n的时候,花费多少 思路:直接存一下每个值所在的位置,然后扫一遍就好了 #include using namespace std; int b[300000]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) {
2016-04-22 23:47:57 415
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人