Codeforces Round#344
A题意思是,给出两个数列,求一个区间,使第一个数列的区间或和第二个数列的区间或的和最大,输出最大和
很显然,或运算会使得答案越运算越大。所以,直接全部或起来,相加就是答案。
= =打cf的时候自动脑补成异或,浪费了好多时间,超出int情况一开始没有考虑,于是加一次重交。
#include <cstdio>
const int N=1005;
long long a[N],b[N]; int n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){scanf("%lld",&a[i]);a[i]|=a[i-1];}
for(int i=1;i<=n;i++){scanf("%lld",&b[i]);b[i]|=b[i-1];}
return printf("%lld\n",a[n]+b[n]),0;
}
B题意思是每次给一整行或者一整列的格子刷上一种颜色,颜色会覆盖之前刷的颜色,问最后每个格子的颜色
这道题如果直接每次操作模拟上色,肯定是会超时的,所以每次记录一个行和一个列被刷的颜色和刷的时间,
那么最后保存下来的就是每一行最后一次刷的颜色和时间以及每个列最后一次刷的颜色和时间。
最后比较一下每个格子列和行的刷新时间,哪个比较迟那么格子就是哪种颜色。
时间戳啊= =,很重要的思想。
#include <cstdio>
int n,m,k,ai,bi,ci,a[50005],b[50005],at[50005],bt[50005];
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=k;i++){
scanf("%d%d%d",&ai,&bi,&ci);
if(ai==1){a[bi]=ci;at[bi]=i;}
else{b[bi]=ci;bt[bi]=i;}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(at[i]>bt[j])printf("%d",a[i]);
else printf("%d",b[j]);
if(j==m)puts("");else printf(" ");
}
}return 0;
}
C题要求支持两种操作,1,r表示把r个数的前缀从小到大排序,2,r表示把r个数的前缀从大到小排序,问最后的序列。
这道题显然,在最长的操作序列前的所有排序都是无效的,同理,在次长和最长的操作序列间的排序是无效的,依次类推。
所以……求降序长度操作序列直接搞?(我当时是这么做的= =,显然,会超时,脑子在想什么呢当时)
最后过题的做法还是时间戳,对于操作的长度位置标上操作的种类,同时记录操作的时间,那么同等长度的显然就可以保存最后一次
在处理完数组之后,逆序操作,保证一个操作的下一个操作时间要比自己晚,也就是……先排一次序,
从后往前依次按照时间戳把序列填充进去,就可以得到答案了。
#include <cstdio>
#include <algorithm>
using namespace std;
int b[200005],c,d,now=1,n,m,a[200005],st,tim,t[200005],op[200005],l[200005];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=m;i++){
scanf("%d%d",&c,&d);
op[d]=c;t[d]=i;
}for(int i=n;i;i--){if(op[i]){st=i;tim=t[i];break;}b[i]=a[i];}
sort(a+1,a+st+1); int flag=0,l=1,r=st;
while(l<=r){
if(op[st]==1&&tim<=t[st]){flag=0;tim=t[st];}
if(op[st]==2&&tim<=t[st]){flag=1;tim=t[st];}
if(flag==0)b[st--]=a[r--];
else b[st--]=a[l++];
}for(int i=1;i<n;i++)printf("%d ",b[i]);
printf("%d\n",b[n]);
return 0;
}
D题的题意简单得不要不要的,就是一个压缩字符串的kmp,
压缩字符串kmp怎么处理呢?简单= =,用pair存字母和数字
那么匹配次数计算就分为以下三种情况:
1. 模式串长度为1,直接枚举,计数原理(显然的)
2. 模式串长度为2,枚举判断是否合法
3. 模式串长度大于等于3,除去头尾扔进kmp进行模式匹配,每次匹配成功判断一下头尾,如果是那么答案加1.
看起来这个算法很完美,嗯,还是fst了,不是算法的问题,过程中数据超出int。
很多时候,还是说,细节决定成败吧。
北京赛区超高的罚时,迎新赛毁于小错误。cf屡屡栽倒在同个错误上。
我还有很长的路要走,在泥泞里多摔倒几次一身狼狈,才能把心沉得更深。
仰之弥高,钻之弥坚。
#include <cstdio>
#include <utility>
using namespace std;
pair<char,long long> s[200005],t[200005],tmp1,tmp2;
int nxt[200005],n,m,cnt1,cnt2;
long long ans,num;
char c;
void kmp(int n,pair<char,long long>*a,int m,pair<char,long long>*b){
int i,j;
for(nxt[0]=j=-1,i=1;i<n;nxt[i++]=j){
while(~j&&a[j+1]!=a[i])j=nxt[j];
if(a[j+1]==a[i])j++;
}
for(j=-1,i=0;i<m;i++){
while(~j&&a[j+1]!=b[i])j=nxt[j];
if(a[j+1]==b[i])j++;
if(j==n-1){
if(i>=n&&b[i+1].first==tmp2.first&&
b[i+1].second>=tmp2.second&&
b[i-n].first==tmp1.first&&b[i-n].second>=tmp1.second)ans++;
j=nxt[j];
}
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf(" %d-%c",&num,&c);
if(s[cnt1].first==c)s[cnt1].second+=num;
else{s[++cnt1].first=c;s[cnt1].second=num;}
}
for(int i=1;i<=m;i++){
scanf(" %lld-%c",&num,&c);
if(t[cnt2].first==c)t[cnt2].second+=num;
else{t[++cnt2].first=c;t[cnt2].second=num;}
}if(cnt2>=3){
tmp1=t[1];tmp2=t[cnt2];
kmp(cnt2-2,t+2,cnt1,s+1);
}else if(cnt2==1){
for(int i=1;i<=cnt1;i++)if(t[cnt2].first==s[i].first&&s[i].second>=t[cnt2].second){
ans+=(long long)(s[i].second-t[cnt2].second+1);
}
}else if(cnt2==2){
for(int i=1;i<cnt1;i++)if(t[1].first==s[i].first&&t[2].first==s[i+1].first
&&t[1].second<=s[i].second&&t[2].second<=s[i+1].second)ans++;
}return printf("%lld\n",ans),0;
}
E题意思是,给出一个数列,现在允许抽出一个数字重新插入,使得最后a[1]*1+a[2]*2+……+a[n]*n最大,求最大值
看别人的代码貌似二分,但是单调性不是很能看得出来,暂且搁置。
Codeforces Round#344的更多相关文章
- Codeforces Round #344 (Div. 2) A. Interview
//http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...
- Codeforces Round #344 (Div. 2) A
A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳
E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...
- Codeforces Round #344 (Div. 2) D. Messenger kmp
D. Messenger 题目连接: http://www.codeforces.com/contest/631/problem/D Description Each employee of the ...
- Codeforces Round #344 (Div. 2) C. Report 其他
C. Report 题目连接: http://www.codeforces.com/contest/631/problem/C Description Each month Blake gets th ...
- Codeforces Round #344 (Div. 2) B. Print Check 水题
B. Print Check 题目连接: http://www.codeforces.com/contest/631/problem/B Description Kris works in a lar ...
- Codeforces Round #344 (Div. 2) A. Interview 水题
A. Interview 题目连接: http://www.codeforces.com/contest/631/problem/A Description Blake is a CEO of a l ...
- Codeforces Round #344 (Div. 2) B. Print Check
B. Print Check time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #344 (Div. 2)(按位或运算)
Blake is a CEO of a large company called "Blake Technologies". He loves his company very m ...
- Codeforces Round #344 (Div. 2)
水 A - Interview 注意是或不是异或 #include <bits/stdc++.h> int a[1005], b[1005]; int main() { int n; sc ...
随机推荐
- mysql——获取所有table名和table字段名。
获取database所有table名: (参考:http://stackoverflow.com/questions/2780284/how-to-get-all-table-names-from-a ...
- org.gradle.process.internal.ExecException:
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ...
- jquery鼠标滑过展示图片时显示详情
jquery: <script src="js/jquery.js" type="text/javascript"></script> ...
- hdu 4634 Swipe Bo bfs+状态压缩
题目链接 状态压缩记录当前拿到了哪些钥匙, 然后暴力搜索. 搞了好几个小时, 一开始也不知道哪里错了, 最后A了也不知道一开始哪里有问题. #include <iostream> #inc ...
- Selenium自动化测试(java语言)
Selenium介绍 Selenium 1.0 包含 core. IDE. RC. grid 四部分, selenium 2.0 则是在两位大牛偶遇相互沟通决定把面向对象结构化( OOPP) 和便于 ...
- Oracle EBS-SQL (SYS-14):查询表空间1.sql
SELECT d.status "状态", d.tablespace_name "名称", d.contents &qu ...
- Redis用户添加、分页、登录、注册、加关注案例
连接redis代码redis.php <?php //实例化 $redis = new Redis(); //连接服务器 $redis->connect("localhost&q ...
- java 中解决中文乱码问题的方法(三法)
1. 重新定义. String str = "中文试试" ; str = new String(u.getBytes("iso-8859-1"),"u ...
- package.json配置项
以下示例列举了常用的地方,一些不常用的可以查看文档:文档地址 { //该模块名字 "name":"test" , //版本 "version" ...
- 内容高度小于窗口高度时版权div固定在底部
<!doctype html><html><head><meta charset="utf-8"><title>文档内容 ...