B. Kefa and Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/problem/B Description Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend wi…
->链接在此<- B. Kefa and Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n fri…
排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typedef long long ll; //#define LOCAL ; struct Node { int m,s; void IN(){ scanf("%d%d",&m,&s); } bool operator < (const Node&rh) const {…
E. Kefa and Watch Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/problem/E Description One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering b…
C. Kefa and Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/problem/C Description Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree con…
A. Kefa and First Steps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/problem/A Description Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) h…
题目链接: 题目 D. Kefa and Dishes time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly…
题目链接:http://www.codeforces.com/problemset/problem/580/A题意:求最长连续非降子序列的长度.C++代码: #include <iostream> using namespace std; ; int n, a[maxn], tmp, ans; int main() { cin >> n; ; i < n; i ++) cin >> a[i]; tmp = ans = ; ; i <= n; i++) ])…
http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有一些规则,x,y,w代表的是如果x吃完后吃y,那么还能获得额外的w欢乐值.计算所能获得的最大欢乐值. 思路: 看到别人说要用状压dp来做,我才恍然大悟啊,感觉自己对于状压dp实在是太不敏感了. d[i][j]表示在当前i状态时最后一份吃的是j的最大欢乐值. 状态转移什么的请看代码吧. #includ…
A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 …
E. Kefa and Watch time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something gli…
A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 …
题目大意:给你一个由0-9组成的字符串,有m个询问,两种操作,第一种将l到r的字符全部变成c,第二种问l到r这段 字符串的循环节是不是d. 思路:首先我们要知道怎么判断字符串的循环节的长度是不是d,如果这个字符串小于等于d,那么肯定是的,否则,如果l 到 r-d 和l+d 到 r 这两段字符串则循环节的长度是d,反之不是. 然后我们就用线段树维护区间字符串哈希值就好啦. #include<bits/stdc++.h> #define read(x) scanf("%d",&…
用spfa,和dp是一样的.转移只和最后一个吃的dish和吃了哪些有关. 把松弛改成变长.因为是DAG,所以一定没环.操作最多有84934656,514ms跑过,实际远远没这么多. 脑补过一下费用流,但是限制流量不能保证吃到m个菜 #include<bits/stdc++.h> using namespace std; typedef pair<int,int> nd; typedef long long ll; #define fi first #define se second…
dfs一遍,维护当前连续遇到的喵的数量,然后剪枝,每个统计孩子数量判断是不是叶子结点. #include<bits/stdc++.h> using namespace std; ; int a[maxn]; ],to[maxn<<],ect; inline void addEdge(int u,int v) { to[ect] = v; nxt[ect] = head[u]; head[u] = ect++; } int ct[maxn],m,cnt; void dfs(int u…
B. Kefa and Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each…
580A. Kefa and First Steps 题目链接: A. Kefa and First Steps 题意描述: 给出一个序列,求最长不降连续子序列多长? 解题思路: 水题,签到 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int main () { int e, s, num, n,…
水 A - Kefa and First Steps /************************************************ * Author :Running_Time * Created Time :2015/9/23 星期三 00:19:33 * File Name :A.cpp ************************************************/ #include <cstdio> #include <algorithm&…
https://codeforces.com/contest/1114/problem/F 欧拉函数 + 区间更新线段树 题意 对一个序列(n<=4e5,a[i]<=300)两种操作: 1. 将a[l,r]的数字乘以x(x<=300) 2. 求\(\varphi(\prod_{i=l}^ra[i])\)对1e9+7取模 题解 欧拉函数性质 假如\(p\)是一个质数,\(\varphi(p)=p-1\),\(\varphi(p^k)=p^{k-1}*(p-1)=p^k*\frac{p-1}…
题意与分析(CodeForces 580D) 一个人有\(n\)道菜,然后要点\(m\)道菜,每道菜有一个美味程度:然后给你了很多个关系,表示如果\(x\)刚好在\(y\)前面做的话,他的美味程度就会增加\(c\).求最大的美味程度. 这种题目一看就是状压dp,\(n \le 15\)啊.定义\(dp[i][stat]\)等于最后一道菜为第i个菜,吃完第i道菜后的状态是stat(第i位为是否吃过,二进制位数的和是吃过菜的总数)的最大美味程度.那么\[dp[i][stat]=max\{dp[j][…
题意与分析(CodeForces 580C) 给你一棵树,然后每个叶子节点会有一家餐馆:你讨厌猫(waht?怎么会有人讨厌猫),就不会走有连续超过m个节点有猫的路.然后问你最多去几家饭店. 这题我写的挫的要死,实际上只需要一次dfs就可以解决了,我愣是用了一次bfs+一次dfs来写--dfs是为了判断是否是叶子节点的....但是bfs干的活完全可以让dfs在找叶子节点的时候顺带解决了,所以就很坑. 一个比较好的写法见https://www.cnblogs.com/qscqesze/p/48315…
题意与分析(CodeForces 580B) \(n\)个人,告诉你\(n\)个人的工资,每个人还有一个权值.现在从这n个人中选出m个人,使得他们的权值之和最大,但是对于选中的人而言,其他被选中的人的工资不能超过他的工资+d. 这题用尺取法可以漂亮的解决.尺取法按照<挑战>一书的定义,是"指对数组保存一对下标(起点和终点),然后根据实际情况交替推进两个端点直到得到答案"的一种方法,因为这种操作"很像是尺蠖(日文中称为尺取虫)爬行的方式"而得名. 具体到这…
原题链接:http://codeforces.com/contest/580/problem/D 题意: 给你一些一个有向图,求不超过m步的情况下,能获得的最大权值和是多少,点不能重复走. 题解: 令$dp[u][s]$为在节点u的时候状态是s的最大值.利用spfa的松弛操作来转移. 代码: #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include&l…
原题链接:http://codeforces.com/contest/580/problem/B 题意: 给你一个集合,集合中的每个元素有两个属性,$m_i,s_i$,让你求个子集合,使得集合中的最大m的差不超过d的情况下,s的和的最大值. 题解: 先排序,然后对于a[i],直接二分a[i].s+d的位置,然后维护一个前缀和,更新答案即可. 代码: #include<iostream> #include<cstring> #include<algorithm> #inc…
原题连接:http://codeforces.com/contest/580/problem/A 题意: 给你一个序列,问你最长不降子串是多长? 题解: 直接模拟就好了 代码: #include<iostream> using namespace std; int n; int main() { cin.sync_with_stdio(false); cin >> n; int p; cin >> p; ) { cout << << endl;…
原题链接: 题意: 给你一棵有根树,某些节点的权值是1,其他的是0,问你从根到叶子节点的权值和不超过m的路径有多少条. 题解: 直接dfs一下就好了. 代码: #include<iostream> #include<cstring> #include<vector> #include<algorithm> #define MAX_N 100005 using namespace std; vector<int> G[MAX_N]; int n,m…
终于补好了. 题目链接: http://codeforces.com/contest/580/problem/E E. Kefa and Watch time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Kefa the parrot was walking down the street as he was on t…
题意:给出一棵树,共有n个节点,其中根节点是Kefa的家,叶子是restaurant,a[i]....a[n]表示i节点是否有猫,问:Kefa要去restaurant并且不能连续经过m个有猫的节点有多少条路径: 思路:先用vector数组建树: 再dfs..(第一次用vector建树,还看了别人的代码,果然是zz): 代码: #include <bits/stdc++.h> #define ll long long #define MAXN 100000+10 using namespace…
C. Kefa and Park time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a roote…
任意门:http://codeforces.com/contest/1114/problem/D D. Flood Fill time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a line of nn colored squares in a row, numbered from 11 to nn f…