A:暴力枚举

模拟

#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n;
int a[N][N];
int main()
{
scanf("%d", &n);
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j)
scanf("%d", &a[i][j]);
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j) if(a[i][j] != )
{
bool flag = false;
for(int x = ; x <= n; ++x) if(x != i)
for(int y = ; y <= n; ++y) if(y != j)
if(a[i][j] == a[x][j] + a[i][y])
{
flag = true;
break;
}
if(!flag)
{
puts("No");
return ;
}
}
puts("Yes");
return ;
}

B:其实我们发现,枚举纵坐标就能枚举出直线上所有的点,然后里面的价值可以O(1)算出,于是枚举纵坐标即可。

模拟

#include<bits/stdc++.h>
using namespace std;
int m, b;
int main()
{
long long ans = ;
scanf("%d%d", &m, &b);
for(long long y = ; y <= b; ++y)
{
long long x = m * b - m * y,
tot = (1ll + x) * x / 2ll * (y + 1ll) + (1ll + y) * y / 2ll * (x + 1ll);
ans = max(ans, tot);
}
printf("%lld\n", ans);
return ;
}

C:这道题挺奥妙的。

脑洞

我们可以维护一个pq,当当前的值和pq的最小值不等时说明要调整。那么我们得问题就在于如何记录当前的值。然后发现这样不好做,因为调整后所有值都变了,那么我们换着一种思路,我们记录到第一个不符合的值之前有多少个符合的。当每次出现不符合的值时,把这个值赋成1,然后累加。每次删除时,我们只要减一,如果减到零了,说明需要调整,那么之前不符合的也符合了,所以之前那些值是没有用的,这样就完成了。

#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n, ans, cnt;
priority_queue<int, vector<int>, greater<int> > q;
int main()
{
scanf("%d", &n);
bool flag = true;
for(int i = ; i <= * n; ++i)
{
char opt[]; scanf("%s", opt);
if(opt[] == 'a')
{
int pos; scanf("%d", &pos);
if(!q.empty() && pos > q.top())
cnt = ; //如果不行了 ,那么肯定需要排序,之前不算
else if(cnt)
++cnt; //如果之前不行,现在行,计算可以不用调整的次数
q.push(pos);
}
if(opt[] == 'r')
{
q.pop();
if(cnt)
{
--cnt; //累计在不行之前能减的次数
if(cnt == ) ++ans;
}
}
}
printf("%d\n", ans);
return ;
}

题解的方法是维护一个栈,每次remove时看是否和应该remove的值相等,相等就弹出,不等就ans+1,把所有元素弹出。这样为什么是对的呢?因为如果当前的数和栈顶相同,那么就是可以的,否则就需要调整。调整完了之后之前的数是有序的,也就不用再调整了,只有进来不可行的才需要调整。(我也理解的不是很透彻,还是上面那个方法直观)

#include<bits/stdc++.h>
using namespace std;
int n, ans, now = ;
stack<int> st;
int main()
{
scanf("%d", &n);
for(int i = ; i <= * n; ++i)
{
char opt[]; scanf("%s", opt);
if(opt[] == 'a')
{
int pos; scanf("%d", &pos);
st.push(pos);
}
if(opt[] == 'r')
{
if(!st.empty())
{
if(now == st.top()) st.pop();
else
{
ans++;
while(!st.empty()) st.pop();
}
}
++now;
}
}
printf("%d\n", ans);
return ;
}

D:这道题写的时候出题人说样例挂了,还有这种操作。。。

最短路

我们发现,只有横纵坐标有一个相差<=2时可以走过去,那么我们就可以考虑建图。这里要分类讨论一下边权的情况,还有终点是否亮。代码里都有了,然后跑最短路就行,可以用deque也可以用dijiestra,dijiestra跑得还挺快。记住不能把边存下来,有n^2条边。

#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
const int N = ;
struct data {
int x, y;
} a[N];
int n, m, k;
priority_queue<PII, vector<PII>, greater<PII> >q;
int d[N], used[N], Q[N];
bool flag = true;
bool cp(data x, data y)
{
return x.x == y.x ? x.y < y.y : x.x < y.x;
}
void dijiestra()
{
memset(used, , sizeof(used));
for(int i = ; i <= k; ++i) d[i] = << ;
q.push(PII(, ));
while(!q.empty())
{
PII x = q.top(); q.pop();
int u = x.second;
if(used[u]) continue;
used[u] = ;
for(int i = ; i <= k; ++i) if(i != u)
if(abs(a[i].x - a[u].x) <= || abs(a[i].y - a[u].y) <= )
{
int w = ;
if((abs(a[i].x - a[u].x) == || abs(a[i].y - a[u].y) == ) && (a[i].x - a[u].x == || a[i].y - a[u].y == ))
w = ;
if(a[i].x == n && a[i].y == m && !flag)
{
w = ;
if((abs(a[i].x - a[u].x) == || abs(a[i].y - a[u].y) == ) && (abs(a[i].x - a[u].x) >= && abs(a[i].y - a[u].y) >= ))
w = << ;
}
if(d[i] > d[u] + w)
{
d[i] = d[u] + w;
q.push(PII(d[i], i));
}
}
}
}
int main()
{
scanf("%d%d%d", &n, &m, &k);
for(int i = ; i <= k; ++i)
scanf("%d%d", &a[i].x, &a[i].y);
sort(a + , a + k + , cp);
if(a[k].x != n || a[k].y != m)
{
flag = false;
a[++k].x = n;
a[k].y = m;
}
dijiestra();
printf("%d\n", d[k] >= << ? - : d[k]);
return ;
}

E:昨天晚上以为这道题组合搞搞就行了。。。

矩阵快速幂

dp:dp[i][x]=dp[i-1][x-1]+dp[i-1][x]+dp[i-1][x+1] 边界不讨论了。

然后这是标准的矩阵快速幂形式,那么对于每条线段构造矩阵,最后一条线段的终点要设成k,初值dp[0][0]=1,输出dp[k][0]。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ;
const ll mod = ;
struct mat {
ll a[][];
} l;
struct data {
ll a, b;
int c;
} a[N];
int n;
ll k;
mat operator * (mat A, mat B)
{
mat ret; memset(ret.a, , sizeof(ret.a));
for(int i = ; i <= ; ++i)
for(int j = ; j <= ; ++j)
for(int k = ; k <= ; ++k)
ret.a[i][j] = (ret.a[i][j] + A.a[i][k] * B.a[k][j] % mod) % mod;
return ret;
}
mat power(mat x, ll t)
{
mat ret; memset(ret.a, , sizeof(ret.a));
for(int i = ; i <= ; ++i)
ret.a[i][i] = ;
for(; t; t >>= , x = x * x) if(t & ) ret = x * ret;
return ret;
}
int main()
{
cin >> n >> k;
for(int i = ; i <= n; ++i)
scanf("%lld%lld%d", &a[i].a, &a[i].b, &a[i].c);
a[n].b= k;
l.a[][] = ;
for(int i = ; i <= n; ++i)
{
mat x; memset(x.a, , sizeof(x.a));
for(int j = ; j <= a[i].c; ++j)
{
if(j > )
x.a[j][j - ] = ;
x.a[j][j] = ;
if(j < a[i].c)
x.a[j][j + ] = ;
}
l = power(x, a[i].b - a[i].a) * l;
}
printf("%lld\n", l.a[][]);
return ;
}

codeforces round #420 div2的更多相关文章

  1. codeforces round 420 div2 补题 CF 821 A-E

    A Okabe and Future Gadget Laboratory 暴力 #include<bits/stdc++.h> using namespace std; typedef l ...

  2. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  3. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  4. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  5. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  6. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  7. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

  8. CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...

  9. Codeforces Round #359 div2

    Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...

随机推荐

  1. jQuery——节点操作

    创建节点 1.$():创建一个li标签 $("<li class='aaa'>我是li标签</li>") 2.html():创建一个li标签并同时添加到ul ...

  2. [Windows Server 2012] 安装Apache+PHP+MySQL

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:Win2012 ...

  3. 零基础学习Python培训,应该选择哪个培训班?

    近几年中,Python一直是市场上最受欢迎的编程语言之一.它语法自然,入门简单,同时应用范围又极广,无论是大火的人工智能.大数据还是传统的web开发.自动化运维,Python都能够大展拳脚.根据职友集 ...

  4. 零基础转行Linux云计算运维工程师获得20万年薪的超级学习技巧

    云计算概念一旦产生便一发不可收拾,成为移动互联网时代最为火热的行业之一.国内各大互联网公司例如阿里.腾讯.百度.网易等纷纷推出自己的云计算产品,3月10日,腾讯云0.01元投标时间更是让云计算在普罗大 ...

  5. C++ 中 字符数组 和 指针 区别

    char str1[] = "abc"; char str2[] = "abc"; const char str3[] = "abc"; c ...

  6. jdk8--collect总结

    https://blog.csdn.net/u014351782/article/details/53818430 一,collect是一个终端操作,它接收的参数是将流中的元素累积到汇总结果的各种方式 ...

  7. 【codeforces 514E】Darth Vader and Tree

    [题目链接]:http://codeforces.com/problemset/problem/514/E [题意] 无限节点的树; 每个节点都有n个儿子节点; 且每个节点与其第i个节点的距离都是ai ...

  8. AndroidTreeView:Android树形节点View

     AndroidTreeView:Android树形节点View AndroidTreeView是github上的一个第三方开源项目,其在github上的项目主页是:https://github. ...

  9. nyoj 307

    /*这是一道最短路变形题 从每个有藏宝的地方为起点 求到各个点的可以的最大重量,相当于求出了从出口 到 一个藏宝点 所  允许的最大重量,把所有藏宝点的按重量 排序(从小到大)先到最小的藏宝点带上 宝 ...

  10. [poj2396]Buget[上下界可行流]

    题意:有一个n*m的方阵,里面的数字未知,但是我们知道如下约束条件:每一行的数字的和每一列的数字的和某些格子有特殊的大小约束,用大于号,小于号和等于号表示问:是否存在用正数填充这个方阵的方案,满足所有 ...