Codeforces Round #419
A
找最近的回文时间
模拟 往后推 判判就行
//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
差分前缀和推一发完事~
//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
贪心
先把整张图能删的都删了 再枚举行、列
输出比较烦
//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
这题好难啊...
把奇数列盖住
(观察?)可得
偶数列 一个数 等于它上一列左边的加上它上一列右边的
别问我怎么观察出来的 我没有观察出来
推到偶数列
杨辉三角
最后判一判剩的是加号还是减号
搞一起就行了..
//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
树形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
线段树 区间覆盖 区间求和...
按照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的更多相关文章
- 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 ...
- Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形dp)
http://codeforces.com/contest/816/problem/E 题意: 去超市买东西,共有m块钱,每件商品有优惠卷可用,前提是xi商品的优惠券被用.问最多能买多少件商品? 思路 ...
- 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 ...
- Codeforces Round #419 (Div. 2) A. Karen and Morning(模拟)
http://codeforces.com/contest/816/problem/A 题意: 给出一个时间,问最少过多少时间后是回文串. 思路: 模拟,先把小时的逆串计算出来: ① 如果逆串=分钟, ...
- Codeforces Round #419 (Div. 2)
1.题目A:Karen and Morning 题意: 给出hh:mm格式的时间,问至少经过多少分钟后,该时刻为回文字符串? 思路: 简单模拟,从当前时刻开始,如果hh的回文rh等于mm则停止累计.否 ...
- 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 ...
- 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 ...
- codeforces round #419 B. Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- 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 ...
- Codeforces Round #419 Div. 1
A:暴力枚举第一列加多少次,显然这样能确定一种方案. #include<iostream> #include<cstdio> #include<cmath> #in ...
随机推荐
- java8的LocalDateTime真心好用(补充Period.between的大坑)
LocalDateTime.LocalDate是java8新增的时间工具类,最近使用后,真心觉得强大好用,推荐文章:https://www.liaoxuefeng.com/article/001419 ...
- How to automate PowerPoint using VB
Microsoft has an article that explains how to automate PowerPoint using VB For some odd reason they' ...
- HDU 1561 树形DP背包问题
这是自己第一道背包上树形结构问题,不是很理解这个概念的可以先看看背包九讲 自己第一次做,看了一下别人的思路,结合着对简单背包问题的求解方式自己一次AC了还是有点小激动的 题目大意是: 攻克m个城市,每 ...
- [luoguP1373] 小a和uim之大逃离(DP)
传送门 题解 代码 #include <cstdio> #include <iostream> #define N 802 #define mod 1000000007 int ...
- 2.1 shuffle sort(洗牌)
1.目的:将数组以随机的顺序重新排序,类似洗牌的过程 2.用途用于快速排序或者任何以划分为基础的排序中,目的是减少最坏可能性发生的概率. 3.想法1:给数组的每一个元素产生一个随机的数字作为键,然后使 ...
- HBase连接数据库(集群)
一.使用java接口对hbase进行表的创建1.引入需要的jar包2.代码: public static void main(String[] args) throws Exception { //得 ...
- Win32编程API 基础篇 -- 2.一个简单的窗口 根据英文教程翻译
一个简单的窗口 例子:简单的窗口 有时人们在IRC提问,”我应该怎样制作一个窗口”...嗯,这恐怕不是完全这么简单好回答!其实这并不难一旦你明白你在做什么,但在你得到一个可展示的窗口之前还有一些事情需 ...
- MEAN,从MONGO DB里弄出点东东来啦,以REST风格显示JSON
最近一直在弄弄的... javascript的风格弄熟了,我觉得肯定很快,,但心中有种感觉,DJANGO和MEAN这种结构,搞大的不行. 因为MVC这种结构感觉不如SPRING这些严谨,是不是我有偏见 ...
- -- > define的用法与学习(1)
在不久之前,我一直不理解为神马大家在做题时经常用define来代替某些函数,或者用来直接定义某些极大的变量.It is not until today that I understand why it ...
- RAC fail over 测试
oracle rac 11gr2中提供了多种 failover方式,这里只测试 server side TAF. 也就是说在server端配置的failover.这种配置方式的好处就是,如果有什么改动 ...