karen

Codeforces Round #419 (Div. 2)

烂漫一生 提交于 2020-03-07 07:17:16
Codeforces Round #419 (Div. 2) http://codeforces.com/contest/816/problem/A A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome? Remember that a palindrome is a string that reads the same forwards

国庆练习4

左心房为你撑大大i 提交于 2020-01-26 04:00:59
Little C Loves 3 I CF 1047A Description Little C loves number « 3» very much. He loves all things about it. Now he has a positive integer n n. He wants to split n n into 3 3 positive integers a , b , c a,b,c, such that a + b + c = n a+b+c=n and none of the 3 3 integers is a multiple of 3 3. Help him to find a solution. Input A single line containing one integer n n ( 3 ≤ n ≤ 10 9 3≤n≤109) — the integer Little C has. Output Print 3 3 positive integers a , b , c a,b,c in a single line, such that a + b + c = n a+b+c=n and none of them is a multiple of 3 3. It can be proved that there is at least

CF815C Karen and Supermarket

落爺英雄遲暮 提交于 2019-12-02 11:57:22
CF815C Karen and Supermarket 树上DP。 首先,考虑建边。显然连一条 \(x[i]->i\) 的边。 其次,考虑DP。那么有数组 \(f[i][j][k]\) 表示 以 \(i\) 为根节点的子树中,选择 \(j\) 件物品的代价; \(k\) 代表是否使用折扣 。 最后看输出。那就看以 \(1\) 为根节点,选择 \(ans\) 件物品,无论打不打折,如果代价小于 \(b\) ,则可行。此外,为了使 \(ans\) 尽量大,所以我们要从 \(n\) 到 \(1\) 遍历寻找答案。 #include<bits/stdc++.h> #define N 5010 using namespace std; int n,b,cnt,ans; int c[N],d[N],x[N],head[N],siz[N],f[N][N][2]; //f[i][j][k] 以i为根节点的子树中,选择j件物品的代价;k代表是否使用折扣 struct node { int nxt,to; }edge[N]; void addEdge(int u,int v) { edge[++cnt]=(node){head[u],v}; head[u]=cnt; return; } void Read() { scanf("%d%d%d%d",&n,&b,&c[1],&d[1]); for

Karen and Supermarket题解

旧巷老猫 提交于 2019-12-02 04:38:10
Karen and Supermarket题解 每个物品只对一个物品有依赖性,所以是一颗树的结构; 但是显然, \(b\) 的范围是 \(1<=b<=1e9\) 存不下, 不能设 \(f[x][i][2]:\) 为以x为节点,i为容量用/不用优惠券的最大物品个数(不能用背包)。 但是我们可以换一换嘛: 设 \(f[x][i][2]\) 为以x为节点,选i个物品用/不用优惠券的最小费用。 若x使用,则儿子可以选择用,也可以不用; x不用,儿子也不能用; 没什么好说的。 #include<bits/stdc++.h> using namespace std; const int N=5006; int n,t,w,siz[N],c[N],d[N],cnt=0,head[N],f[N][N][2]; struct edge{int nxt,to;}e[N<<1]; inline void add(int u,int v){e[++cnt].nxt=head[u],e[cnt].to=v,head[u]=cnt;} inline int read(){ int T=0,F=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') F=-1; ch=getchar();} while(ch>='0'&&ch<='9') T=(T<<3)+

[CF815C] Karen and Supermarket

梦想与她 提交于 2019-12-01 13:53:20
问题描述 On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars. The supermarket sells n goods. The i -th good can be bought for ci dollars. Of course, each good can only be bought once. Lately, the supermarket has been trying to increase its business. Karen, being a loyal customer, was given n coupons. If Karen purchases the i -th good, she can use the i -th coupon to decrease its price by di . Of course, a coupon cannot be used

codeforces 816B Karen and Coffee (差分思想)

会有一股神秘感。 提交于 2019-11-27 05:20:20
题目链接 816B Karen and Coffee 题目分析 题意:有个人在学泡咖啡,因此看了很多关于泡咖啡温度的书,得到了n种推荐的泡咖啡温度范围[L1,R1] ,此人将有k种做法推荐的温度记为可用温度(个人翻译),然后给出q次询问,问区间[L2,R2]内的温度,有多少个温度是可用温度(每个整数代表一个温度) 思路:一开始用的是线段树写的,不过姿势不对,TLE了,然后改过来后,发现时间比较长,就考虑一下优化的方法。 比线段树某些功能更优的算法:差分思想,在对某一区间每个位置上的数加上一个值x,并求任意位置的数的时候,时间上比线段树 O(nlogn)的复杂度更低,为O(n),空间更小,代码更短,很合适。 那么如何运用差分思想来写这个题呢?首先用O(n)的时间求出每个温度有多少种做法推荐,然后维护一个前缀和sum[i],记录区间 [1, i ] 表示的温度中有多少个温度满足条件(即有多少个温度有k种以上做法推荐),用O(n)的时间求出sum数组,sum[i] = sum[i-1] + (val[i] >= k ? 1 : 0;) ,最后查询区间[ L2,R2]有多少适合的温度时,输出 sum[R2] - sum[L2-1] 。 (不了解什么是差分的话,可以看下我的这篇博客 差分+树上差分 ) 代码区 #include<iostream> #include<cstdio>