A.直接判断每一个数。

#include<bits/stdc++.h>
using namespace std; int n,a[][]; int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++)
{
for(int j = ;j <= n;j++) cin >> a[i][j];
}
for(int i = ;i <= n;i++)
{
for(int j = ;j <= n;j++)
{
if(a[i][j] == ) continue;
int flag = ;
for(int ii = ;ii <= n;ii++)
{
for(int jj = ;jj <= n;jj++)
{
if(a[ii][j]+a[i][jj] == a[i][j]) flag = ;
}
}
if(!flag)
{
cout << "No" << endl;
return ;
}
}
}
cout << "Yes" << endl;
return ;
}

B.枚举直线上每一点,x,y坐标分开算,求和公式。

#include<bits/stdc++.h>
using namespace std; long long m,b; int main()
{
ios::sync_with_stdio();
cin >> m >> b;
long long ans = ;
for(int y = ;y <= b;y++)
{
long long x = (b-y)*m;
ans = max(ans,(x+)*(y+)*y/+(y+)*(x+)*x/);
}
cout << ans << endl;
return ;
}

C.模拟栈,每次需要整理的时候,把栈中所有出栈,因为底下的已经有序,不需要再去关注它们。

#include<bits/stdc++.h>
using namespace std; int n;
stack<int> s;
string ss; int main()
{
ios::sync_with_stdio();
cin >> n;
int now = ,ans = ;
for(int i = ;i <= *n;i++)
{
cin >> ss;
if(ss == "add")
{
int x;
cin >> x;
s.push(x);
}
else
{
if(s.empty())
{
now++;
continue;
}
if(now == s.top())
{
s.pop();
now++;
}
else
{
ans++;
now++;
while(!s.empty()) s.pop();
}
}
}
cout << ans << endl;
return ;
}

D.直接O(k^2)的最短路,转移的时候若两个点相邻,则dis不用+1,若某一坐标之差≤2,则可以转移dis+1,若终点不lit,设一个(n+1,m+1)的点,最后结果回自动+1。

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std; int n,m,k,x[],y[],vis[] = {},dis[] = {}; int main()
{
ios::sync_with_stdio();
cin >> n >> m >> k;
int s,t = ;
for(int i = ;i <= k;i++)
{
cin >> x[i] >> y[i];
if(x[i] == && y[i] == ) s = i;
if(x[i] == n && y[i] == m) t = i;
}
if(!t)
{
t = ++k;
x[k] = n+;
y[k] = m+;
}
memset(dis,0x3f,sizeof(dis));
dis[s] = ;
for(int j = ;j <= k;j++)
{
int pos = -,minn = INF;
for(int i = ;i <= k;i++)
{
if(!vis[i] && dis[i] < minn)
{
pos = i;
minn = dis[i];
}
}
if(pos == -) break;
vis[pos] = ;
for(int i = ;i <= k;i++)
{
if(vis[i]) continue;
if(abs(x[pos]-x[i])+abs(y[pos]-y[i]) == ) dis[i] = min(dis[i],dis[pos]);
else if(abs(x[pos]-x[i]) <= || abs(y[pos]-y[i]) <= ) dis[i] = min(dis[i],dis[pos]+);
}
}
if(dis[t] == INF) cout << - << endl;
else cout << dis[t] << endl;
return ;
}

E.对于每一段,可以dp,矩阵快速幂优化,注意每一段结束和每一段开始的时候,把高于c点的值清零。

#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std; int n;
long long k;
struct xx
{
long long m[][];
}; xx mul(xx a,xx b,int len)
{
xx tmp;
for(int i = ;i <= len;i++)
{
for(int j = ;j <= len;j++)
{
tmp.m[i][j] = ;
for(int k = ;k <= len;k++) tmp.m[i][j] = (tmp.m[i][j]+a.m[i][k]*b.m[k][j])%MOD;
}
}
return tmp;
} xx qpower(xx a,long long k,int len)
{
xx b;
memset(b.m,,sizeof(b.m));
for(int i = ;i <= len;i++) b.m[i][i] = ;
while(k)
{
if(k%) b = mul(a,b,len);
a = mul(a,a,len);
k /= ;
}
return b;
}
int main()
{
ios::sync_with_stdio();
cin >> n >> k;
xx base,now;
for(int i = ;i < ;i++)
{
for(int j = max(,i-);j < min(i+,);j++) base.m[i][j] = ;
}
now.m[][] = ;
for(int i = ;i <= n;i++)
{
long long a,b,c;
cin >> a >> b >> c;
for(int j = c+;j < ;j++) now.m[j][] = ;
now = mul(qpower(base,min(b,k)-a,c),now,c);
for(int j = c+;j < ;j++) now.m[j][] = ;
if(b >= k) break;
}
cout << now.m[][] << endl;
return ;
}

Codeforces_821的更多相关文章

随机推荐

  1. 7.netty内存管理-ByteBuf

    ByteBuf ByteBuf是什么 ByteBuf重要API read.write.set.skipBytes mark和reset duplicate.slice.copy retain.rele ...

  2. linux入门系列3--常见的linux远程登陆管理工具

    服务器一般是云服务器或者放置在机房,我们日常工作中通过远程连接工具连接到服务器进行操作,这类工具很多(如SecureCRT.XShell.Putty.FinallShell.TeamViewer以及w ...

  3. Spark设置Kryo序列化缓冲区大小

    背景 今天在开发SparkRDD的过程中出现Buffer Overflow错误,查看具体Yarn日志后发现是因为Kryo序列化缓冲区溢出了,日志建议调大spark.kryoserializer.buf ...

  4. FIND_IN_SET 精确查找

    FIND_IN_SET(str,strlist) mysql专为精确匹配字符串而设置的函数 一个字符串列表就是一个由一些被‘,’符号分开的自链组成的字符串 1,2,3,4,5,6,7,8,9: 此函数 ...

  5. 28.python操作excel表格(xlrd/xlwt)

    python读excel——xlrd 这个过程有几个比较麻烦的问题,比如读取日期.读合并单元格内容.下面先看看基本的操作: 首先读一个excel文件,有两个sheet,测试用第二个sheet,shee ...

  6. Spring Boot从零入门2_核心模块详述和开发环境搭建

    目录 1 前言 2 名词术语 3 Spring Boot核心模块 3.1 spring-boot(主模块) 3.2 spring-boot-starters(起步依赖) 3.3 spring-boot ...

  7. 一些常用查询SQL语句以及显示格式

    1.查询当前年.月.周相关时间 1.1.查询当前年份 SELECT TO_CHAR(SYSDATE,'YYYY') AS YEAR FROM DUAL--查询当前年份 SELECT TO_CHAR(S ...

  8. 1、使用 as 而不要用 is

    public class ShouldAsNotIs { public void ShouldAs() { object a = new ShouldAsNotIs(); var b = a as S ...

  9. 从源码角度了解SpringMVC的执行流程

    目录 从源码角度了解SpringMVC的执行流程 SpringMVC介绍 源码分析思路 源码解读 几个关键接口和类 前端控制器 DispatcherServlet 结语 从源码角度了解SpringMV ...

  10. 【C&数据结构】---关于链表结构的前序插入和后序插入

    刷LeetCode题目,需要用到链表的知识,忽然发现自己对于链表的插入已经忘得差不多了,以前总觉得理解了记住了,但是发现真的好记性不如烂笔头,每一次得学习没有总结输出,基本等于没有学习.连复盘得机会都 ...