cf C. Inna and Dima】的更多相关文章

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; ;…
Inna and Dima 题意:从图上的任意一个D点按着DIMADIMA的顺序走,问一共可以经过多少个DIMA,如果经过0个DIMA就输出“Pool DIma!“,如果可以有无数多个DIMA就输出”Pool Inna!",否则就输出个数. 题解:DFS搜索就好了,这里我刚开的时候思考的是每次从不同的D点是给每个点标记都不同,然后会遇到从一个D点走的不同路并且不产生环的时候无法检查(菜死我了),后面发现如果产生环的时候,4个环的转弯点是方向是一定的,所以只要每次进行dfs的时候标记一下,从这个点…
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…
题目大意是有一个DIMA四种字母组成的矩阵,要在矩阵中找最长的DIMADIMADIMA……串,连接方式为四方向连接,问最长能找到多少DIMA.字母可以重复访问,如果DIMA串成环,即可以取出无限长的DIMA串,则输出特定字符串,若没有DIMA串,也输出另一特定字符串,否则输出最长多少DIMA串. 这是我大一暑假的时候做的,并且当时WA在第23组上,后来就没继续做这个题了,现在不想看大一的代码了. 重新想了一下,其实就是判图中是否有环,无环的话,DIMA的链最长多少,也就是找图中以D字母开头的最长…
题面传送门 解决思路 本题是找最长路的图上问题,所以先考虑如何建图. 首先把每一个字母转化为数字,然后对于每一个点枚举四个方向,如果有下一个字母,就向那个点建一条边,可以用 \(vector\) 存图比较方便.用数字标号,只需要判断 \(t_{x2,y2}=(t_{x1,y1}+1)\mod 4\) 是否成立即可,但直接用字母判断也是比较方便的. 然后考虑 \(\text{dfs}\) 搜索可以走的最长路.有以下几个注意点: 开始搜索的点一定是 D. 已经更新过答案的点就不用搜了,直接 \(\t…
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题,要注意超边界... #include <iostream> #include <cstring> #include <algorithm> using namespace std; <<); int n,m,x,y,a,b; int ok(int x1,int…
题意:给你一个长度为n的只含有1和0的字符串,w个询问,每次询问输入l,r:在[l,r]中在l+k-1.l+2*k-1.......r的位置都必须为1,如果不为1的,变成1,记为一次操作,其它的地方的都必须为0,不为0的地方要变成1,也记为一次操作,最后问在区间[l,r]最少几次操作. 思路:可以用树状数组记录在某个地方的右方有多少个1,然后在 预处理出从1,2,..k的为开头的在i+c*k-1的位置上前面有多少个1,最后的答案是拿走的1+添加的1,拿走的1的个数等于现有的1的个数-位置正确的1…
题意:输入n,然后输入n个数ai,再输入n个数bi,如果在1-ai中能找到两个数x,y,x和y可以相等,如果x+y=bi,答案加上x*y,否则减去1,让结果尽可能大,输出结果. #include <cstdio> #include <cstring> #include <algorithm> #define ll long long #define maxn 100100 using namespace std; int n; ll a[maxn],b[maxn]; i…
http://codeforces.com/contest/374/problem/B #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ]; int main() { while(scanf("%s",str)!=EOF) { int k=strlen(str); __int64 ans=; ; i<k;) { ]-&&…
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…
B. Dima and To-do List time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends…
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 ha…
 Dima and Guards Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with S…
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…
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…
A. Inna and Choose Options time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusu…
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 …
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 two…
收录已发布的题解 按发布时间排序. 部分可能与我的其他文章有重复捏 qwq . AtCoder for Chinese: Link ZHOJ: Link 洛谷 \(1\sim 5\) : [题解]CF45I TCMCF+++ [题解]CF1013B And [题解]CF991C Candies [题解]CF356A Knight Tournament [题解]CF1715A Crossmarket \(6\sim 10\) : [题解]CF1215C Swap Letters [题解]CF172…
http://codeforces.com/contest/366/problem/D 遍历下界,然后用二分求上界,然后用dfs去判断是否可以. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 10000 using namespace std; int n,m; int head[maxn]; bool vis[maxn]; int e; int pl[maxn],pr[ma…
http://codeforces.com/problemset/problem/366/D 题意:给出n个点,m条边,a,b,ll,rr分别代表点a,点b相连,点a和点b的区间范围(ll,rr),然后让你选择边相连接使得可以从点1到点n,并且所有被选择的边所共同覆盖的区间范围最大. 4 41 2 1 102 4 3 51 3 1 52 4 2 7 64个点,4条边,现在可以从1--2--4,存在两条路径,(1,10)--(3,5)或者(1,10)——(2,7),要选择这所共同覆盖的区间范围最大…
C. Dima and Salad 题意 有n种水果,第i个水果有一个美味度ai和能量值bi,现在要选择部分水果做沙拉,假如此时选择了m个水果,要保证\(\frac{\sum_{i=1}^ma_i}{\sum_{i=1}^mb_i}==k\),问沙拉最大的美味度是多少? 思路 01背包变形. 对于给出的公式,我们化简一下: \(\sum_{i=1}^ma_i-k*\sum_{i=1}^mb_i==0\) 就变成了把a[i]-k*b[i]作为体积,a[i]作为价值,向容量为0的背包里放,可以取得的…
题目链接:http://codeforces.com/problemset/problem/366/E 题意:给出一个n*m的数字矩阵A,每个矩阵元素的范围[1,K].给出一个长度为s的数字串B,B的每个元素的范围[1,K].将B中的每个元素t用A中的一个位置(i,j)代替,满足A[i][j]=B[t].这样就得到一个长度为s的位置序列.定义相邻两个位置的距离为曼哈顿距离,定义序列的最大距离为每两个相邻元素距离最大值.求一种替换方案使得序列的最大距离最大. 思路:最后转化成两个位置集合S1,S2…
http://codeforces.com/contest/366/problem/E |x1-x2|+|y1-y2|有四种情况 1.-(x1-x2)+(y1-y2); 2.(x1-x2)-(y1-y2); 3.-(x1-x2)-(y1-y2); 4.(x1-x2)+(y1-y2); 可以先把没一个数的坐标分为上面的四种情况存起来,然后在S序列相邻的两个数的曼哈顿距离最大就是两个数中的一个数的四种情况最大值减去另一个数的最小值. #include <cstdio> #include <c…
http://codeforces.com/contest/366/problem/C 转化为背包问题,可以将a[i]-b[i]*k看成重量,a[i]为价值: 因为a[i]-b[i]*k可以为负数,所以应该分开讨论.结果就是dp[10000],如果等于0则输出-1,否则输出dp[10000]; #include <cstdio> #include <cstring> #include <algorithm> #define maxn 500005 using names…
http://codeforces.com/contest/366/problem/B 从0到k枚举起点,然后i+k判断是不是i+k>=n如果是i=(i+k)%n;否则i=i+k; #include <cstdio> #include <cstring> #include <algorithm> #define maxn 200010 using namespace std; <<; int n,k; int a[maxn]; bool vis[max…
http://codeforces.com/contest/358/problem/D 题意:ai代表相邻的两个野兔都没有吃食物情况下的快乐系数,bi代表的是在相邻的两个野兔中有一个吃到食物的快乐系数,ci代表的是相邻的两个野兔都迟到事物的快乐系数,给你n个野兔的快乐系数,求最大快乐系数. dp[i][0]表示先于i+1个吃到食物的最大快乐系数,dp[i][1]表示后于i+1个吃到食物的最大快乐系数. #include <cstdio> #include <cstring> #in…
http://codeforces.com/contest/358/problem/C 将最大的放在stack里面,第二大的放在queue中,第三大的放在deck里面.然后模拟就可以了. #include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespace std; ]; priority_queue<int ,vector<int&g…