Codeforces Round #427 (Div. 2) [ C. Star sky ] [ D. Palindromic characteristics ] [ E. The penguin's game ]
本来准备好好打一场的,然而无奈腹痛只能带星号参加 (我才不是怕被打爆呢!)
PROBLEM C - Star sky
题
OvO http://codeforces.com/contest/835/problem/C
835C
解
由于题目中给的c很小,可以对应每种亮度分别保存(c+1)个矩阵
然后初始化一下求前缀矩阵
每次询问就可以O(c)求出答案
(Accepted)
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std; const int M=144;
const int MM=100; int mp[M][M][20];
int pre[M][M][20];
int n,q,c;
int ans; void init()
{
int i,j,k;
memset(pre,0,sizeof(pre));
for(i=1;i<=MM;i++)
for(j=1;j<=MM;j++)
for(k=0;k<=c;k++)
pre[i][j][k]=pre[i-1][j][k]+pre[i][j-1][k]-pre[i-1][j-1][k]+mp[i][j][k];
} int main()
{
int chg,tmp,i,j,x,y,z,x1,y1,x2,y2,t;
cin>>n>>q>>c;
memset(mp,0,sizeof(mp));
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&z);
mp[x][y][z]++;
}
init();
while(q--)
{
scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2);
ans=0;
for(i=0;i<=c;i++)
{
chg=(i+t)%(c+1);
tmp=pre[x2][y2][i]-pre[x1-1][y2][i]-pre[x2][y1-1][i]+pre[x1-1][y1-1][i];
ans+=tmp*chg;
}
cout<<ans<<endl;
}
return 0;
}
PROBLEM D - Palindromic characteristics
题
OWO http://codeforces.com/contest/835/problem/D
835D
解
对每两点做字符串哈希,然后搜索加记忆化(每搜索一段到一段合法的继续搜左右两边,递归,得到该段的类型,并且用类型来标记该段已经搜过)
这样搜索的时间是O(n*n),然后O(1)判断哈希值是否相等,是的话就把对应计数值+1
pretest能过,最后会不会挂掉就看我取的模了(趁终测还没结束赶紧睡觉~☆)(没挂嘿嘿嘿)
(Accepted)
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm> using namespace std; typedef unsigned long long ull; const int M=5022;
const int bas=14123; int ans[M];
char s[M];
int num[M];
int n;
unsigned hsh[M][M];
int flag[M][M]; void init()
{
int i,j;
n=strlen(s+1);
for(i=1;i<=n;i++)
{
if(s[i]>='a')
num[i]=s[i]-'a';
else
num[i]=s[i]-'A'+26;
}
memset(ans,0,sizeof(ans));
memset(flag,-1,sizeof(flag));
for(i=1;i<=n;i++)
{
hsh[i][i]=num[i];
for(j=i+1;j<=n;j++)
hsh[i][j]=hsh[i][j-1]*bas+num[j];
for(j=i-1;j>=1;j--)
hsh[i][j]=hsh[i][j+1]*bas+num[j];
}
} bool fj(int a,int b,int c,int d)
{
return true;
int i,j;
for(i=a,j=d;i<=b;i++,j--)
if(num[i]!=num[j])
return false;
return true;
} int check(int a,int d)
{
if(a==d)
{
flag[a][d]=1;
return 1;
}
int tmp=(d-a+1)/2;
int b,c;
b=a+tmp-1; c=d-tmp+1;
// cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<hsh[a][b]<<' '<<hsh[d][c]<<endl;
if(hsh[a][b]==hsh[d][c] && fj(a,b,c,d))
{ int flag0,flag1,flag2; if(flag[a][b]!=-1)
flag1=flag[a][b];
else
{
flag1=check(a,b);
flag[a][b]=flag1;
ans[flag1]++;
} if(flag[c][d]!=-1)
flag2=flag[c][d];
else
{
flag2=check(c,d);
flag[c][d]=flag2;
ans[flag2]++;
}
flag0=min(flag1,flag2);
return flag0+1;
}
else
{
flag[a][d]=0;
return 0;
}
} void solve()
{
int i,j,a,b,c,d,len,tmp;
for(i=1;i<=n;i++)
{
for(j=i;2*j-i<=n;j++)
{
if(2*j-i<=n)
{
a=i; d=2*j-i; len=d-a+1;
if(flag[a][d]==-1)
{
tmp=check(a,d);
flag[a][d]=tmp;
ans[tmp]++;
}
}
if(2*j-i+1<=n)
{
a=i; d=2*j-i+1; len=d-a+1;
if(flag[a][d]==-1)
{
tmp=check(a,d);
flag[a][d]=tmp;
ans[tmp]++;
}
}
}
}
for(i=n;i>=1;i--)
ans[i]+=ans[i+1];
for(i=1;i<=n;i++)
{
if(i-1) printf(" ");
printf("%d",ans[i]);
}
printf("\n");
} int main()
{
int i,j;
scanf("%s",s+1);
init();
solve();
return 0;
}
一结束我就写了题解 怎么会有我这么勤奋的人呢 我真是太了不起了~☆
PROBLEM E - The penguin's game
题
OwO http://codeforces.com/contest/835/problem/E
835E
解
设要不同的2个点为p,q
1. n的范围为1000,所以最多有10位。所以可以枚举每一位,对该为为1的数字输出,这样可以知道p,q哪些位数不同。(至多10次输出)
2. p,q不同的位的数量至少为1。所以可以随便选取一位,然后,选出该位为1的数字,放入集合中,则这个集合中最多只有1个特殊点(设其为p),所以可以二分区间寻找改p(至多9次输出)
3. 找到p点之后,根据第1步中得到的p和q中各位的关系,得到q
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> using namespace std; const int N=33;
const int M=1111; int n,x,y;
int dif[N],chs;
int se[N][M],lse[N];
int rep; void ask(int len,int s[])
{
printf("? %d",len);
for(int i=1;i<=len;i++)
printf(" %d",s[i]);
printf("\n");
fflush(stdout);
scanf("%d",&rep);
} void output(int ans1,int ans2)
{
printf("! %d %d\n",ans1,ans2);
fflush(stdout);
} void init()
{
int i,j,mdl;
memset(lse,0,sizeof(lse));
for(i=1;i<=n;i++)
{
for(j=0;j<10;j++)
{
mdl=(1<<j);
if(i&mdl)
se[j][++lse[j]]=i;
}
}
chs=-1;
memset(dif,0,sizeof(dif));
for(i=0;i<10;i++)
if(lse[i]!=0)
{
ask(lse[i],se[i]);
if(rep!=0 && rep!=x)
{
dif[i]=1;
if(chs==-1)
chs=i;
}
}
} void solve()
{
int ans1,ans2;
int s[M],ls;
int i,j,tmp;
ls=0;
for(i=1;i<=n;i++)
if(i&(1<<chs))
s[++ls]=i;
int li,ri,mid;
// for(i=1;i<=ls;i++)
// cout<<s[i]<<' ';
// cout<<endl;
li=1; ri=ls;
while(li!=ri)
{
mid=(li+ri)>>1;
ask((mid-li+1),s+li-1);
if(rep==0 || rep==x)
li=mid+1;
else
ri=mid;
}
ans1=s[li];
ans2=ans1^(1<<chs);
for(i=0;i<10;i++)
if(i!=chs && dif[i]==1)
ans2^=(1<<i);
if(ans1>ans2) swap(ans1,ans2);
output(ans1,ans2);
} int main()
{
cin>>n>>x>>y;
init();
solve();
return 0;
}
Codeforces Round #427 (Div. 2) [ C. Star sky ] [ D. Palindromic characteristics ] [ E. The penguin's game ]的更多相关文章
- 动态规划:Codeforces Round #427 (Div. 2) C Star sky
C. Star sky time limit per test2 seconds memory limit per test256 megabytes inputstandard input outp ...
- CF Round #427 (Div. 2) C. Star sky [dp]
题目链接就长这样子? time limit per test 2 seconds memory limit per test 256 megabytes Description The Carte ...
- CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)
s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...
- CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)
证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...
- Codeforces Round #427 (Div. 2)—A,B,C,D题
A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...
- Codeforces Round #427 (Div. 2)
B. The number on the board 题意: 有一个数字,它的每个数位上的数字的和不小于等于k.现在他改变了若干位,变成了一个新的数n,问现在的数和原来的数最多有多少位不同. 思路: ...
- Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...
- Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...
- 【Codeforces Round #427 (Div. 2) C】Star sky
[Link]:http://codeforces.com/contest/835/problem/C [Description] 给你n个星星的坐标(xi,yi); 第i个星星在第t秒,闪烁值变为(s ...
随机推荐
- Redis(1.1)linux下安装redis
一.常见安装方式 [0]环境 OS:CentOS7.5 Redis:4.0.14 yum源:本地源 [1]检查安装 gcc 依赖环境 gcc -v#如果没安装会报错类似于 command not fi ...
- Springmvc使用注解实现执行定时任务(定时器)
1.在Spring配置文件中添加 <task:annotation-driven/> 2.在需要调用执行定时任务的类中使用注解 @Service @Lazy(false) //避免spri ...
- ASP.NET Core中使用Dapper
⒈添加 NuGet 包 Install-Package Dapper ⒉封装数据库类型 using System; using System.Collections.Generic; using Sy ...
- Swoft 2.0.3 重大更新,发布优雅的微服务治理
 什么是 Swoft ? Swoft 是一款基于 Swoole 扩展实现的 PHP 微服务协程框架.Swoft 能像 Go 一样,内置协程网络服务器及常用的协程客户端且常驻内存,不依赖传统的 PHP ...
- jQuert DOM操作
DOM操作 1 内部插入 append(content|fn) 向每个匹配的元素内部追加内容 appendTo(content) 把所有匹配的元素追加到另一个指定的元素元素集合中 prepend(co ...
- linux命令 ip
- Hello World!!!
C #include <stdio.h> int main() #main 入口函数 { printf("Hello,World!"); #printf 函数打印 ; ...
- CF 666C & 牛客 36D
给定字符串S, 求有多少长为$n$的字符串T, 使得S为T的子序列. 可以得到转移矩阵为 $\begin{equation}A=\begin{bmatrix}25 & 0 & 0 &a ...
- 缓存策略:redis缓存之springCache
最近通过同学,突然知道服务器的缓存有很多猫腻,这里通过网上查询其他人的资料,进行记录: 缓存策略 比较简单的缓存策略: 1.失效:应用程序先从cache取数据,没有得到,则从数据库中取数据,成功后,放 ...
- java语言中使用三元式的时候应该注意的问题
今天在项目中改领导要求的代码表现的时候发现了一个很有趣的问题. 但是的代码情况类似如下: 1 2 Integer test1 = null; System.out.println("test ...