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 ...
随机推荐
- 带你全面分析嵌入式linux系统启动过程中uboot的作用
资料链接:http://mp.weixin.qq.com/s/rYVchD-xy7Bdkc1O3fW2Wg
- [BZOJ2843] 极地旅行社(LCT)
传送门 模板. ——代码 #include <cstdio> #include <iostream> #define N 300001 #define get(x) (son[ ...
- node.js 核心http模块,起一个服务器,返回一个页面
let http=require("http"); //引入核心http模块 let fs=require("fs"); let mime={ '.js':'a ...
- Linux 使用pwgen命令创建随机密码
https://blog.csdn.net/fdipzone/article/details/73864598 http://www.netkou.com/?post=155
- Codeforces Goodbye2016
A =w= B 0.0 C 题意:按顺序给出一个人一年参加cf比赛的信息,包括是div1还是div2,赛后rating的增减多少,求出这个人现在rating最多可能为多少 分析:模拟 设这个人刚开始分 ...
- [Vue-rx] Watch Vue.js v-models as Observable with $watchAsObservable and RxJS
You most likely already have data or properties in your template which are controlled by third-party ...
- 调试JDK源代码-一步一步看HashMap怎么Hash和扩容
调试JDK源代码-一步一步看HashMap怎么Hash和扩容 调试JDK源代码-ConcurrentHashMap实现原理 调试JDK源代码-HashSet实现原理 调试JDK源代码-调试JDK源代码 ...
- LeetCode 234. Palindrome Linked List (回文链表)
Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time ...
- PHP数字左侧自动补零
1.输出数字为001,002... <?php $number=0; if($number<100) { $number=$number+1; $txt=sprintf("%03 ...
- HDFS03
=====================HDFS数据块(block)===================== 文件被切分成固定大小的数据块 -------------> √默认数据块大小为6 ...