A

Karen and Morning

找最近的回文时间

模拟  往后推 判判就行

//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
int tx,ty,T;
bool check(){
int rx=tx/,ry=tx%;
return ry*+rx==ty;
}
int main(){
scanf("%d:%d",&tx,&ty);
while(){
if(check()){printf("%d\n",T);return ;}
T++,ty++;
if(ty==)tx++,ty=;
if(tx==)tx=;
}
}

B

Karen and Coffee

差分前缀和推一发完事~

//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
const int N=;
int n,k,q,xx,yy,a[N],s[N];
int main(){
scanf("%d%d%d",&n,&k,&q);
for(int i=;i<=n;i++)scanf("%d%d",&xx,&yy),a[xx]++,a[yy+]--;
for(int i=;i<N;i++)a[i]+=a[i-];
for(int i=;i<N;i++)s[i]=s[i-]+(a[i]>=k);
for(int i=;i<=q;i++)scanf("%d%d",&xx,&yy),printf("%d\n",s[yy]-s[xx-]);
}

C

Karen and Game

贪心

先把整张图能删的都删了  再枚举行、列

输出比较烦

//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
const int N=;
int n,m,a[N][N],minn=N,rec[N],recl[N],T;
int main(){
scanf("%d%d",&n,&m);memset(rec,0x3f,sizeof(rec));memset(recl,0x3f,sizeof(recl));
for(int i=;i<=n;i++)for(int j=;j<=m;j++)scanf("%d",&a[i][j]),minn=min(minn,a[i][j]);
for(int i=;i<=n;i++)for(int j=;j<=m;j++)a[i][j]-=minn;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++)rec[i]=min(rec[i],a[i][j]);
for(int j=;j<=m;j++)a[i][j]-=rec[i];
}
for(int i=;i<=n;i++)for(int j=;j<=m;j++)if(a[i][j]!=a[][j]){puts("-1");return ;}else recl[j]=min(recl[j],a[i][j]);
for(int i=;i<=n;i++)for(int j=;j<=rec[i];j++)T++;
for(int i=;i<=m;i++)for(int j=;j<=recl[i];j++)T++;
if(n<m)for(int i=;i<=minn;i++)for(int j=;j<=n;j++)T++;
else for(int i=;i<=minn;i++)for(int j=;j<=m;j++)T++;
printf("%d\n",T);
for(int i=;i<=n;i++)for(int j=;j<=rec[i];j++)printf("row %d\n",i);
for(int i=;i<=m;i++)for(int j=;j<=recl[i];j++)printf("col %d\n",i);
if(n<m)for(int i=;i<=minn;i++)for(int j=;j<=n;j++)printf("row %d\n",j);
else for(int i=;i<=minn;i++)for(int j=;j<=m;j++)printf("col %d\n",j);
}

D

Karen and Test

这题好难啊...

把奇数列盖住

(观察?)可得

偶数列 一个数 等于它上一列左边的加上它上一列右边的

别问我怎么观察出来的  我没有观察出来

推到偶数列

杨辉三角

最后判一判剩的是加号还是减号

搞一起就行了..

//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
const int N=,mod=;
int n,a[N],ans1,ans2,tot,fac[N],inv[N];
int C(int x,int y){return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;}
int pow(int x,int y){
int r=;
while(y){
if(y&)r=1ll*r*x%mod;
x=1ll*x*x%mod,y>>=;
}return r;
}
int main(){
scanf("%d",&n),fac[]=;
for(int i=;i<=n;i++)scanf("%d",&a[i]),tot+=i-;
for(int i=;i<=n;i++)fac[i]=1ll*fac[i-]*i%mod;
for(int i=;i<=n;i++)inv[i]=pow(fac[i],mod-);
if(n==){printf("%d\n",a[]);return ;}
if(n&){
for(int i=;i<n;i++)a[i]=i&?(a[i]+a[i+]):(a[i]-a[i+]);n--;
}
for(int i=;i<=n;i+=)ans1=(ans1+1ll*a[i]*C(n/-,i/))%mod;
for(int i=;i<=n;i+=)ans2=(ans2+1ll*a[i]*C(n/-,i/-))%mod;
printf("%d\n",((tot&?(ans1+ans2)%mod:ans1-ans2)+mod)%mod);
}

E

Karen and Supermarket

树形DP

f[x][j]  x子树必须用优惠券 选了j个

g[x][j] x子树必须不用优惠券 选了j个

g[x]->g[x]

f[x]&g[x]->f[x]

//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
const int N=;
int first[N],nxt[N],v[N],tot,c[N],d[N],fa[N],n,k,f[N][N],g[N][N],size[N],ans;
void add(int x,int y){v[tot]=y,nxt[tot]=first[x],first[x]=tot++;}
void dfs(int x){
f[x][]=g[x][]=,size[x]=;g[x][]=c[x];
for(int i=first[x];~i;i=nxt[i]){
dfs(v[i]);
for(int j=size[x];~j;j--){
for(int k=size[v[i]];~k;k--){
f[x][j+k]=min(f[x][j+k],f[x][j]+f[v[i]][k]);
}
}
for(int j=size[x];~j;j--){
for(int k=size[v[i]];~k;k--){
g[x][j+k]=min(g[x][j+k],g[x][j]+g[v[i]][k]);
}
}
size[x]+=size[v[i]];
}
for(int i=size[x];i;i--)f[x][i]=min(g[x][i],f[x][i-]+c[x]-d[x]);
}
int main(){
memset(first,-,sizeof(first));
memset(f,0x3f,sizeof(f));
memset(g,0x3f,sizeof(g));
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
scanf("%d%d",&c[i],&d[i]);
if(i!=)scanf("%d",&fa[i]),add(fa[i],i);
}dfs();
for(int i=;i<=n;i++)if(f[][i]<=k)ans=i;
printf("%d\n",ans);
}

Div1 D

Karen and Cards

线段树 区间覆盖 区间求和...

按照a排序 那么从大到小  nowb>b[i]||nowc>c[i]

用总方案数减去不合法的

就是all-左下角的一块矩形

a变小的时候  就会有nowb>b[i]&&nowc>c[i]

就把一块都覆盖住就好了

x轴是b y轴是c  单调递减

//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=;
typedef long long ll;
int n,a,b,c,minn[N*],maxx[N*],lazy[N*];
ll sum[N*],ans;
struct Node{int x,y,z;}node[N];
void setlazy(int num,int pos,int wei){sum[pos]=1ll*num*wei;maxx[pos]=minn[pos]=lazy[pos]=wei;}
void push_down(int l,int r,int pos){
int mid=(l+r)>>,lson=pos<<,rson=lson|;
setlazy(mid-l+,lson,lazy[pos]),setlazy(r-mid,rson,lazy[pos]);
lazy[pos]=;
}
void push_up(int pos){
int lson=pos<<,rson=lson|;
sum[pos]=sum[lson]+sum[rson],minn[pos]=min(minn[lson],minn[rson]),maxx[pos]=max(maxx[lson],maxx[rson]);
}
void insert(int l,int r,int pos,int L,int R,int wei){
if(wei<=minn[pos])return;
if(lazy[pos])push_down(l,r,pos);
if(l>=L&&r<=R&&maxx[pos]<=wei){setlazy(r-l+,pos,wei);return;}
int mid=(l+r)>>,lson=pos<<,rson=pos<<|;
if(mid<L)insert(mid+,r,rson,L,R,wei);
else if(mid>=R)insert(l,mid,lson,L,R,wei);
else insert(l,mid,lson,L,R,wei),insert(mid+,r,rson,L,R,wei);
push_up(pos);
}
bool cmp(Node a,Node b){return a.x>b.x;}
int main(){
scanf("%d%d%d%d",&n,&a,&b,&c);
for(int i=;i<=n;i++){
scanf("%d%d%d",&node[i].x,&node[i].y,&node[i].z);
insert(,b,,,node[i].y,node[i].z);
}sort(node+,node++n,cmp);
for(int i=a,j=;i;i--){
for(;j<=n&&node[j].x==i;j++)insert(,b,,,node[j].y,c),insert(,b,,,b,node[j].z);
ans+=1ll*b*c-sum[];
}printf("%I64d\n",ans);
}

Div1 E  不会-> ->

Codeforces Round #419的更多相关文章

  1. Codeforces Round #419 D. Karen and Test

    Karen has just arrived at school, and she has a math test today! The test is about basic addition an ...

  2. Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形dp)

    http://codeforces.com/contest/816/problem/E 题意: 去超市买东西,共有m块钱,每件商品有优惠卷可用,前提是xi商品的优惠券被用.问最多能买多少件商品? 思路 ...

  3. Codeforces Round #419 (Div. 2) B. Karen and Coffee(经典前缀和)

    http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs s ...

  4. Codeforces Round #419 (Div. 2) A. Karen and Morning(模拟)

    http://codeforces.com/contest/816/problem/A 题意: 给出一个时间,问最少过多少时间后是回文串. 思路: 模拟,先把小时的逆串计算出来: ① 如果逆串=分钟, ...

  5. Codeforces Round #419 (Div. 2)

    1.题目A:Karen and Morning 题意: 给出hh:mm格式的时间,问至少经过多少分钟后,该时刻为回文字符串? 思路: 简单模拟,从当前时刻开始,如果hh的回文rh等于mm则停止累计.否 ...

  6. codeforces round #419 E. Karen and Supermarket

    On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a ...

  7. codeforces round #419 C. Karen and Game

    C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...

  8. codeforces round #419 B. Karen and Coffee

    To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...

  9. codeforces round #419 A. Karen and Morning

    Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As yo ...

  10. Codeforces Round #419 Div. 1

    A:暴力枚举第一列加多少次,显然这样能确定一种方案. #include<iostream> #include<cstdio> #include<cmath> #in ...

随机推荐

  1. python爬虫26 | 把数据爬取下来之后就存储到你的MySQL数据库。

    小帅b说过 在这几篇中会着重说说将爬取下来的数据进行存储 上次我们说了一种 csv 的存储方式 这次主要来说说怎么将爬取下来的数据保存到 MySQL 数据库 接下来就是 学习python的正确姿势 真 ...

  2. 分金币 (UVA 11300)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33899 思路:推公式,发现可以转化为求给定n个数,求到所有点距离之和最小的点 ...

  3. java 使用OpenOffice文件实现预览

    1.安装OpenOffice软件 安装教程:https://jingyan.baidu.com/article/c275f6ba12c07ce33d756732.html 2.安装完成后,创建项目,p ...

  4. Java基础学习总结(84)——Java面向对象六大原则和设计模式

    面向对象六大原则 在此之前,有一点需要大家知道,熟悉这些原则并不是说你写出的程序就一定灵活.清晰,只是为你优秀的代码之路铺上了一层栅栏,在这些原则的指导下,你才能避免陷入一些常见的代码泥沼,从而让你写 ...

  5. 定时任务-----Springboot中使用Scheduled做定时任务----http://www.cnblogs.com/lirenqing/p/6596557.html

    Springboot中使用Scheduled做定时任务---http://www.cnblogs.com/lirenqing/p/6596557.html 已经验证的方案: pom文件加入依赖 < ...

  6. MVC系统学习2—MVC路由

    在MVC下不是通过对物理文件的映射来实行访问的,而是通过定义后的路由Url来实现访问的.在前一篇讲到我们是在全局文件下进行路由配置. routes.MapRoute(                & ...

  7. [luoguP3565] [POI2014]HOT-Hotels(dfs)

    传送门 三点在树上距离相等的情况只有一种,就是以某一个点为中心,三个点到这个点的距离相等. 所以直接枚举每个点作为中心,dfs这个中心的子树,根据乘法原理统计答案即可. 时间复杂度 O(n2) (n ...

  8. hdu 2089 记忆化搜索写法(数位dp)

    /* 记忆化搜索,第二维判断是否是6 */ #include<stdio.h> #include<string.h> #define N 9 int dp[N][2],digi ...

  9. multiple instance of mac app

    一般情况下,mac系统上的应用程序只能启动一个实例,现在做项目,需要mac上同时启动多个实例,如何做呢,下面就说明完成这个功能的方法: 主要原理:利用 open -n Applications/XXX ...

  10. alpha版出炉,实现win2008 service的session 0穿透

    指定用户名,拿最小session,实现和用户ui交互. 这样,搞windows的自动化部署,就可以向前一大步啦. 比以前用psexec要用户名密码,指定session要先进多啦. 安全保密性也提高了. ...