Codeforces 374C - Inna and Dima】的更多相关文章

374C - Inna and Dima 思路:dfs+记忆化搜索 代码: #include<bits/stdc++.h> using namespace std; #define ll unsigned long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) const int INF=0x3f3f3f3f; ][]; ][]; ][]; ][]={,,,,,-,-,}; int n,m; int dfs(i…
Inna and Dima 题意:从图上的任意一个D点按着DIMADIMA的顺序走,问一共可以经过多少个DIMA,如果经过0个DIMA就输出“Pool DIma!“,如果可以有无数多个DIMA就输出”Pool Inna!",否则就输出个数. 题解:DFS搜索就好了,这里我刚开的时候思考的是每次从不同的D点是给每个点标记都不同,然后会遇到从一个D点走的不同路并且不产生环的时候无法检查(菜死我了),后面发现如果产生环的时候,4个环的转弯点是方向是一定的,所以只要每次进行dfs的时候标记一下,从这个点…
http://codeforces.com/contest/374/problem/C 记忆化搜索,题意:求按照要求可以记过名字多少次,如果次数为无穷大,输出Poor Inna!,如果不经过一次输出Poor Dima!,否则输出输出次数. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 1001 #define LL __int64 using namespace std; ;…
题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行  m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动到四个角落(1,1),(1,m),(n, 1),(n, m) 中的其中一个.假设当前在位置(x, y),规定每次移动遵循,(x+a, y+b) . (x+a, y-b). (x-a, y+b).(x-a, y-b).求最小的移动次数. 求出 (i, j) 到每个角落的距离diff_x, diff_y…
原题地址:http://codeforces.com/contest/374/problem/A 好久没写题目总结了,最近状态十分不好,无论是写程序还是写作业还是精神面貌……NOIP挂了之后总觉得缺乏动力精神难以集中……CF做的也是一塌糊涂,各种pretest passed + fail system test,该拿下的总是拿不下,都掉成Specialist了,也不知是什么原因,一点点尽力调整吧这是道水题,本来Div2的第一题就没什么好总结的,但是这道题为整场比赛创造了无数Hack得分(不得不吐…
题目大意是有一个DIMA四种字母组成的矩阵,要在矩阵中找最长的DIMADIMADIMA……串,连接方式为四方向连接,问最长能找到多少DIMA.字母可以重复访问,如果DIMA串成环,即可以取出无限长的DIMA串,则输出特定字符串,若没有DIMA串,也输出另一特定字符串,否则输出最长多少DIMA串. 这是我大一暑假的时候做的,并且当时WA在第23组上,后来就没继续做这个题了,现在不想看大一的代码了. 重新想了一下,其实就是判图中是否有环,无环的话,DIMA的链最长多少,也就是找图中以D字母开头的最长…
Inna and Choose Options Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 400A64-bit integer IO format: %I64d      Java class name: (Any)   There always is something to choose from! And now, instead of…
题目描述: Inna and Nine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have m…
题面传送门 解决思路 本题是找最长路的图上问题,所以先考虑如何建图. 首先把每一个字母转化为数字,然后对于每一个点枚举四个方向,如果有下一个字母,就向那个点建一条边,可以用 \(vector\) 存图比较方便.用数字标号,只需要判断 \(t_{x2,y2}=(t_{x1,y1}+1)\mod 4\) 是否成立即可,但直接用字母判断也是比较方便的. 然后考虑 \(\text{dfs}\) 搜索可以走的最长路.有以下几个注意点: 开始搜索的点一定是 D. 已经更新过答案的点就不用搜了,直接 \(\t…
题目链接:http://codeforces.com/problemset/problem/499/A 题目意思:有两种按钮:1.如果当前观看的时间是 t,player 可以自动处理下一分钟,姑且理解为跳到t+1:  2.直接跳过 x 分钟,如果player在第 t 分钟,则可以跳到 t+x 分钟.问恰好可以看完 n 部电影的最少观看时间.观看一部电影(假如为第 i 部,起始时间为 li, 结束时间为 ri)表示 li, li+1, li+2, ..., ri-1, ri 的时间都要覆盖到. 一…
原题地址:http://codeforces.com/problemset/problem/374/B 这道题没什么难度,但是考场上就是没写对.Round #220彰显了它的逗比性质——这道题的“标算”在赛场上被推翻了.而且最有意思的是,我最初的想法和被推翻的标算是一样的,所以过了最初的pretest,然后改了数据就跪了,考后的后两天也没想出当时的想法反例在哪里,直到昨晚瞄了一眼数据才相通……还是想法.编程能力,再不提升我就彻底要跪了 题目大意:给你n个数(n <= 10000),所有数都是1-…
http://codeforces.com/problemset/problem/400/C 题意:给你一个n*m的矩阵,然后在矩阵中有p个糖果,给你每个糖果的初始位置,然后经过x次顺时针反转,y次旋转,z次逆时针反转,问最后每个糖果的位置. 思路:推出顺时针反转.旋转.逆时针反转的坐标的变化即可. #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #defin…
374D - Inna and Sequence 思路: 树状数组+二分 因为被删的点最多N=1e6个,所以复杂度N*logN*logN 前段时间做过一道一样的题,这类题基本套路二分找没删除前的位置 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) ; int n; int bit[N]…
                                                                       E. Dima and Kicks                                                              time limit per test 2 seconds                                                              memory li…
题目链接:http://codeforces.com/problemset/problem/400/C 题目意思:给出一个n行m列的矩阵,问经过 x 次clockwise,y 次 horizontal rotate 和z次counterclockwise 之后,原来在n行m列的矩阵的坐标去到哪个位置. 题目意思很容易看懂.易知,对于clockwise,counterclockwise的次数,mod 4 == 0 相当于没有改变!而对于 horizontal rotate,mod 2 == 0 也…
本题的主要算法就是区间更新和区间求和: 可以用线段树和树状数组来做: 感觉线段树写的太麻烦了,看到官方题解上说可以用树状数组做,觉得很神奇,以前用过的树状数组都是单点维护,区间求和的: 其实树状数组还可以区间维护,单点求值:和区间维护,区间求和的: 详情请见博客. #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #define maxn 4000010 #define…
几个小结论: 1.路径长度=i+j-1; 2.最简单的走法是先横走再竖着走或者先竖着走再横着走 #include<cstdio> #include<cstring> using namespace std; void print(int x,int y) { ; i<=y; i++) printf("(1,%d) ",i); ; i<=x; i++) printf("(%d,%d) ",i,y); printf("\n&…
这个题目看似不是很好下手,不过很容易发现每次询问的时候总是会问到第r个盒子是否有糖果: 这样的话就很好办事了: 维护两个数组: 一个sum数组:累加和: 一个in数组:如果i位是1的话,in[i]=in[i-k]+1;否则不加1,很好理解: 然后利用in数组可以找到本来应该有糖果的但是没有糖果的箱子的数目: 然后结合sum数组就可以的出结果: #include<cstdio> #include<cstring> #define maxn 100005 using namespace…
题目链接 给m个数, n个操作, 一个数列, 初始为空.一共有3种操作, 在数列末尾加0, 加1, 或删除位置为a[i]的数, a[i]为初始给的m个数, 如果a[i]大于数列长度, 那么什么也不发生. 求最后的数列. 用线段树, 因为最多只有n个操作, 也就是说最后的01串最大长度为n, 那么可以用一个变量now表示当前插入的话应该插入到哪个位置, 每插入一个数, now就加1,并且now最终不会超过n. 删除操作的话, 递归的进行, 如果sum[rt<<1]大于要删除的下标那么就往左儿子递…
题目链接 给出n个数, 定义a[1][i]为这初始的n个数, 然后a[i][j] = a[i-1][j]&a[i-1][j-1], 这样就可以得到一个三角形一共n*(n-1)/2个数. 给出一种操作, 将a[1][x]这个位置的数换为y, 然后求换完之后的这n(n-1)/2个数的和. 很有意思的题, 这个题应该按位建线段树, 这样需要建18棵, 因为a[1][i]的最大值为1e5. 然后我们来看具体如何做, 我们来看一组数据:3 6 7, 换为二进制之后是下面这个样子. 0 1 1 1 1 0…
主题链接:点击打开链接 特定n一个操作,m长序列a 下列n的数量 if(co>=0)向字符串加入一个co (開始是空字符串) else 删除字符串中有a的下标的字符 直接在序列上搞.简单模拟 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h&…
树状数组仅仅能实现线段树区间改动和区间查询的功能,能够取代不须要lazy tag的线段树.且代码量和常数较小 首先定义一个数组 int c[N]; 并清空 memset(c, 0, sizeof c); 1.单点改动 : c[x] += y; 相应的函数是 change(x, y); 2.求前缀和 :  相应的函数是 int sum(x) 两种操作的复杂度都是O(logn) 模板例如以下: int c[N], maxn; inline int Lowbit(int x){return x&(-x…
题目链接:点击打开链接 题意:给定n*m的二维平面 w个操作 int mp[n][m] = { 0 }; 1.0 (x1,y1) (x2,y2) value for i : x1 to x2 for j : y1 to y2 mp[i][j] += value; 2.1 (x1, y1) (x2 y2) ans1 = 纵坐标在 y1,y2间的总数 ans2 = 横坐标不在x1,x2间的总数 puts(ans1-ans2); more format: for i : 1 to n for j :…
题面: 传送门 题目描述: 题意很简单:在一个N*M的矩阵中(N行M列),问是否可以:每行选一个整数,使他们的异或和大于0.如果不可以,输出"NIE":如果可以,输出"TAK",并输出选择的整数.   题目分析: 这道题刚开始想直接暴力,但看到复杂度竟然是O(500^500),就怂了.到后面仔细观察,发现题目有个数据:每个数小于1024,也就是2^10次方.会不会跟数位有关?后面分析了一下,果然是,但没时间做了,不过结束后还是A出来了.   异或(求大佬无视):转化…
Inna and Huge Candy Matrix CodeForces - 400C Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from …
C. Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to…
C. Dima and Salad   Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has…
Codeforces#262_1002 B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him…
C. Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to…
A - Inna and Choose Options Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of…