本来打算划划水洗洗睡了,突然听到这次的主人公是冈部伦太郎

石头门(《steins;gate》)主题的比赛,岂有不打之理!

石头门真的很棒啊!人设也好剧情也赞曲子也特别好听。

推荐http://music.163.com/#/m/song?id=26259014&userid=115264555

(强行跑题)

Okabe and Future Gadget Laboratory

O(n^4)暴力妥妥的

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
vector<int>r[],c[];
int mp[][];
int check(int a,int x,int y){
for(int i=;i<r[x].size();i++){
for(int j=;j<c[y].size();j++){
if(r[x][i]+c[y][j]==a)return ;
}
}
return ;
}
int main(){
int i,j;
int n=read();
for(i=;i<=n;i++){
for(j=;j<=n;j++){
mp[i][j]=read();
r[i].push_back(mp[i][j]);
c[j].push_back(mp[i][j]);
}
}
for(i=;i<=n;i++){
for(j=;j<=n;j++){
if(mp[i][j]==)continue;
if(!check(mp[i][j],i,j)){
printf("NO\n");
return ;
}
}
}
printf("YES\n");
return ;
}

A

Okabe and Banana Trees

枚举 扫描

发现枚举横坐标最多需要枚举1e7次

推一下收益的式子就可以了。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL calc(LL x,LL y){
LL res=(+y)*y/*(x+);
res+=(+x)*x/*y;
res+=(+x)*x/;
return res;
}
LL ans=;
int main(){
int i,j;
int m,b;
m=read();b=read();
for(int i=;i>=;i++){
int y=b-ceil((double)i/m);
if(y<)break;
ans=max(ans,calc(i,y));
}
printf("%I64d\n",ans);
return ;
}

B

Okabe and Boxes

贪心 构造

显然当不能满足要求的出栈序的时候就要把栈内元素排序。

真的都排序的话复杂度受不了,只存还没有排过序的就可以了

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
priority_queue<int>q;
int last,ord;
int n,x;
char s[];
int st[mxn],top=;
int main(){
int i,j;
n=read();
int ed=n<<;
ord=;
int ans=;
for(i=;i<=ed;i++){
// printf("i:%d\n",i);
scanf("%s",s);
if(s[]=='a'){
scanf("%d",&x);
q.push(-x);
st[++top]=x;
last=x;
}
else{//remove
if(last==ord){
q.pop();
ord++;
if(top)top--;
if(top){
last=st[top];
}
else last=-q.top();
}
else{
ans++;
ord++;
q.pop();
last=-q.top();
top=;
}
}
// printf("top:%d last:%d\n",q.top(),last);
}
printf("%d\n",ans);
return ;
}

C

Okabe and City

图论 最短路 脑洞题

正解是把每行每列看做一个点,在这些点和原有的点之间花式连边跑最短路。

然而博主用非显式建边的方法暴力跑了一发过去了。

只要有1w个点全在一行的数据就能把我的方法卡掉。。

  ↑然而没有这种数据233

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct edge{
int v,nxt;
}e[mxn<<];
int hd[mxn],mct=;
void add_edge(int u,int v){
e[++mct].v=v;e[mct].nxt=hd[u];hd[u]=mct;return;
}
void insert(int u,int v){
add_edge(u,v);add_edge(v,u);
}
int n,m,K;
struct point{
int x,y;
}a[mxn];
vector<int>r[mxn],c[mxn];
int f[mxn];
queue<int>q;
bool inq[mxn];
void SPFA(int st){
memset(f,0x3f,sizeof f);
q.push(st);f[st]=;
while(!q.empty()){
int u=q.front();q.pop();inq[u]=;
// if(f[u]>f[K])continue; // nope!
int x=a[u].x;
for(int i=;i<r[x].size();i++){
int v=r[x][i],cost=(abs(a[u].y-a[v].y)==)?:;
if(f[v]>f[u]+cost){
f[v]=f[u]+cost;
if(!inq[v]){
inq[v]=;
q.push(v);
}
}
}
//
for(int i=;i<r[x+].size();i++){
int v=r[x+][i],cost=;
if(f[v]>f[u]+cost){
f[v]=f[u]+cost;
if(!inq[v]){
inq[v]=;
q.push(v);
}
}
}
for(int i=;i<r[x+].size();i++){
int v=r[x+][i],cost=;
if(f[v]>f[u]+cost){
f[v]=f[u]+cost;
if(!inq[v]){
inq[v]=;
q.push(v);
}
}
}
for(int i=;i<r[x-].size();i++){
int v=r[x-][i],cost=;
if(f[v]>f[u]+cost){
f[v]=f[u]+cost;
if(!inq[v]){
inq[v]=;
q.push(v);
}
}
}
if(x>){
for(int i=;i<r[x-].size();i++){
int v=r[x-][i],cost=;
if(f[v]>f[u]+cost){
f[v]=f[u]+cost;
if(!inq[v]){
inq[v]=;
q.push(v);
}
}
}
}
//
int y=a[u].y;
for(int i=;i<c[y].size();i++){
int v=c[y][i],cost=(abs(a[u].x-a[v].x)==)?:;
if(f[v]>f[u]+cost){
f[v]=f[u]+cost;
if(!inq[v]){
inq[v]=;
q.push(v);
}
}
}
for(int i=;i<c[y-].size();i++){
int v=c[y-][i],cost=;
if(f[v]>f[u]+cost){
f[v]=f[u]+cost;
if(!inq[v]){
inq[v]=;
q.push(v);
}
}
}
if(y>){
for(int i=;i<c[y-].size();i++){
int v=c[y-][i],cost=;
if(f[v]>f[u]+cost){
f[v]=f[u]+cost;
if(!inq[v]){
inq[v]=;
q.push(v);
}
}
}
}
for(int i=;i<c[y+].size();i++){
int v=c[y+][i],cost=;
if(f[v]>f[u]+cost){
f[v]=f[u]+cost;
if(!inq[v]){
inq[v]=;
q.push(v);
}
}
}
for(int i=;i<c[y+].size();i++){
int v=c[y+][i],cost=;
if(f[v]>f[u]+cost){
f[v]=f[u]+cost;
if(!inq[v]){
inq[v]=;
q.push(v);
}
}
}
/*
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
// printf("u:%d v:%d\n",u,v);
if(f[v]>f[u]+1){
f[v]=f[u]+1;
if(!inq[v]){
inq[v]=1;
q.push(v);
}
}
}
*/
}
return;
}
map<int,int>mp[mxn];
int main(){
int i,j;
n=read();m=read();K=read();
for(i=;i<=K;i++){
a[i].x=read();a[i].y=read();
r[a[i].x].push_back(i);
c[a[i].y].push_back(i);
mp[a[i].x][a[i].y]=i;
}
//
/*
for(i=1;i<=K;i++){
if(mp[a[i].x+1][a[i].y+1]){
insert(i,mp[a[i].x+1][a[i].y+1]);
}
if(mp[a[i].x-1][a[i].y+1]){
insert(i,mp[a[i].x-1][a[i].y+1]);
}
}
*/
for(i=;i<=K;i++){
if(a[i].x== && a[i].y==){
SPFA(i);break;
}
}
int ans=0x3f3f3f3f;
for(i=;i<=K;i++){
// printf("i:%d f:%d\n",i,f[i]);
if(a[i].x==n && a[i].y==m)ans=min(ans,f[i]);
if(a[i].x>=n- || a[i].y>=m-)ans=min(ans,f[i]+);
}
if(ans==0x3f3f3f3f)ans=-;
printf("%d\n",ans);
return ;
}

D

代码看着长,其实只要写一小段,其他都是复制的

Okabe and El Psy Kongroo

数学问题 递推 矩阵乘法

应该跟D换一下的,明显这个更简单

看到矩阵乘法就能明白了吧233

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
using namespace std;
const int mod=1e9+;
LL read(){
LL x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int sz=;
struct Mat{
int x[][];
void clear(){
memset(x,,sizeof x);return;
}
void init(int n){
for(int i=;i<=n;i++)x[i][i]=;return;
}
Mat operator * (const Mat b){
Mat res;
for(int i=;i<=sz;i++){
for(int j=;j<=sz;j++){
res.x[i][j]=;
for(int k=;k<=sz;k++){
res.x[i][j]=((LL)res.x[i][j]+(LL)x[i][k]*b.x[k][j]%mod)%mod;
}
}
}
return res;
}
void debug(){
for(int i=;i<=sz;i++){
for(int j=;j<=sz;j++){
printf("%d ",x[i][j]);
}
puts("");
}
puts("");
return;
}
};
Mat ans,bas,aa;
Mat ksm(Mat a,LL k){
Mat res;res.clear();res.init(sz);
while(k){
if(k&)res=res*a;
a=a*a;
k>>=;
}
return res;
}
int n;LL K;
void Build(int lim){
bas.clear();
for(int i=;i<=lim;i++){
bas.x[i][i]=;
if(i)bas.x[i][i-]=;
if(i<lim)bas.x[i][i+]=;
}
return;
}
int main(){
int i,j;
n=read();K=read();
ans.init();sz=;
LL a,b;int c;
int last=;
for(i=;i<=n;i++){
a=read();b=read();c=read();
if(a>=K)break;
Build(c);
b=min(b,K);
aa=ksm(bas,b-a);
ans=ans*aa;
}
printf("%d\n",ans.x[][]);
return ;
}

E

Codeforces Round #420 (Div. 2) A-E的更多相关文章

  1. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  2. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  3. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  4. Codeforces Round #420 (Div. 2) - C

    题目链接:http://codeforces.com/contest/821/problem/C 题意:起初有一个栈,给定2*n个命令,其中n个命令是往栈加入元素,另外n个命令是从栈中取出元素.你可以 ...

  5. Codeforces Round #420 (Div. 2) - E

    题目链接:http://codeforces.com/contest/821/problem/E 题意:起初在(0,0),现在要求走到(k,0),问你存在多少种走法. 其中有n条线段,每条线段为(a, ...

  6. Codeforces Round #420 (Div. 2) - B

    题目链接:http://codeforces.com/contest/821/problem/B 题意:二维每个整点坐标(x,y)拥有的香蕉数量为x+y,现在给你一个直线方程的m和b参数,让你找一个位 ...

  7. Codeforces Round #420 (Div. 2) - A

    题目链接:http://codeforces.com/contest/821/problem/A 题意:给定一个n*n的矩阵. 问你这个矩阵是否满足矩阵里的元素除了1以外,其他元素都可以在该元素的行和 ...

  8. Codeforces Round #420 (Div. 2)

    /*************************************************************************************************** ...

  9. Codeforces Round #420 (Div. 2) A,B,C

    A. Okabe and Future Gadget Laboratory time limit per test 2 seconds memory limit per test 256 megaby ...

  10. Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo 矩阵快速幂优化dp

    E. Okabe and El Psy Kongroo time limit per test 2 seconds memory limit per test 256 megabytes input ...

随机推荐

  1. 配置ip,使你的虚拟机可以被别人访问到,搭建服务器必备

    我么一般配置虚拟机的时候,我们总是喜欢使用虚拟网段,但是这样别人有可能ping不通我的虚拟机的. 若是我们想要别人ping我们的ip ,则我们要跟改以下几个操作: 在我们的网络源的源模式中,你若是想在 ...

  2. app测试更多机型系统解决方法

    手头上测试机有限,不可能每个机型每个系统都 有一部手机,此时寻求一个什么都有的测试平台就显得尤为重要了. 作为小白的我刚刚使用了一波腾讯优测,简单粗暴有效给力,而且新注册认证用户还有60min免费使用 ...

  3. rfid工作原理

    RFID的工作原理是:标签进入磁场后,如果接收到阅读器发出的特殊射频信号,就能凭借感应电流所获得的能量发送出存储在芯片中的产品信息(即Passive Tag,无源标签或被动标签),或者主动发送某一频率 ...

  4. 阿里中间件RocketMQ

    阿里RocketMQ是怎样孵化成Apache顶级项目的? RocketMQ 迈入50万TPS消息俱乐部 Apache RocketMQ背后的设计思路与最佳实践 专访RocketMQ联合创始人:项目思路 ...

  5. 51nod-1227-平均最小公倍数

    题意 定义 \(n\) 的平均最小公倍数: \[ A(n)=\frac{1}{n}\sum _{i=1}^n\text{lcm}(n,i) \] 求 \[ \sum _{i=L}^RA(i) \] \ ...

  6. bzoj3517 翻硬币

    题意 有一个n行n列的棋盘,每个格子上都有一个硬币,且n为偶数.每个硬币要么是正面朝上,要么是反面朝上.每次操作你可以选定一个格子(x,y),然后将第x行和第y列的所有硬币都翻面.求将所有硬币都变成同 ...

  7. Day22-CSRF跨站请求伪造

    csrf 跨站请求伪造 一.简介 django为用户实现防止跨站请求伪造的功能,通过中间件 django.middleware.csrf.CsrfViewMiddleware 来完成. 1.1 第1次 ...

  8. 【BZOJ2879】【NOI2012】美食节(费用流)

    [BZOJ2879][NOI2012]美食节(费用流) 题面 BZOJ 洛谷 题解 一眼就会思路了吧. 把每个厨师拆点,拆分为他最多能要做的菜的个数,即\(\sum p_i\) 然后把每个菜向厨师的每 ...

  9. python基础----isinstance(obj,cls)和issubclass(sub,super)、反射、__setattr__,__delattr__,__getattr__、二次加工标准类型(包装)

    一.isinstance(obj,cls)和issubclass(sub,super)                                isinstance(obj,cls)检查是否ob ...

  10. [USACO09OPEN] 工作调度Work Scheduling (贪心/堆)

    [USACO09OPEN] 工作调度Work Scheduling 题意翻译 约翰有太多的工作要做.为了让农场高效运转,他必须靠他的工作赚钱,每项工作花一个单位时间. 他的工作日从0时刻开始,有10^ ...