A.很水的题目,3个for循环就可以了

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char str[];
int main()
{
cin>>str;
int ans = ;
int L = strlen(str);
for(int i = ; i < L; i++)
for(int j = i+; j < L; j++)
for(int k = j+; k < L; k++)
if(str[i] == 'Q' && str[j] == 'A' && str[k] == 'Q') ans++;
cout<<ans<<endl;
return ;
}

B.如果存在解,那么答案就是2^(x-1)(y-1),然后快速幂就可以了。

实际上就是判断(x-1)*(y-1)都填1有没有解,如果有的话,其实你变换任意一个矩阵内元素的值都有对应的唯一一种情况成立。

注意费马小定理和long long的溢出问题。

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + ;
LL mypow(LL a, LL b){
LL ans = ; for(; b; b>>=, (a*=a)%=MOD) if(b&) (ans*=a)%=MOD;return ans;
}
LL x, y, k;
int main()
{
cin>>x>>y>>k;
if( ((x+y)&) && k == -){
cout<<<<endl;
return ;
}
cout<<mypow(, ((x-)%(MOD-)) *((y-)%(MOD-)) %(MOD-))<<endl;
return ;
}

C.首先必定有一个元素是所有元素的gcd,否则就是无解。

然后这个gcd也必定是最小的,令它为g,那么我们只需要把g插入到原序列中,就可以保证两两之间的gcd被限制到g,就满足了要求。

这个构造还是挺巧妙的。

#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = ;
int a[maxn], n;
int H[];
int gcd(int x, int y) { return x % y == ? y : gcd(y, x%y); }
int main()
{
cin>>n;
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
int ans = a[];
for(int i = ; i <= n; i++) ans = gcd(ans, a[i]);
if(ans != a[]){
cout<<"-1"<<endl;
return ;
}
cout<<*n-<<endl;
cout<<a[]<<" ";
for(int i = ; i <= n; i++){
cout<<a[]<<" "<<a[i]<<" ";
}
}

D.树是二叉树,就很好做了

每个结点保存子树中到它的距离集合

答案就是子树内满足要求的点的个数n*h和它们的距离和的差,就是n*h - sum

查询这个用二分查找就可以了

注意到非子树内也有满足要求的点,

解决这个问题只需要沿着祖先往上爬就可以了,沿途统计答案。

这里使用了upper_bound,还是很好用的。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1e6 + ;
long long v[maxn][];
vector<long long> D[maxn], Sum[maxn];
long long getsum(int k, int i, int j){
if(i > j) return ;
return i- < ? Sum[k][j] : Sum[k][j] - Sum[k][i-];
}
int main()
{
int n, m, x, a, h;
cin>>n>>m;
for(int i = ; i < n; i++) {
scanf("%d", &x);
v[(i+)/][(i+)%] = x;
}
for(int i = n; i >= ; i--){
D[i].push_back();
if(i* <= n){
for(auto x : D[i*])
D[i].push_back(x+v[i][]);
}
if(i*+ <= n){
for(auto x : D[i*+])
D[i].push_back(x+v[i][]);
}
sort(D[i].begin(), D[i].end());
Sum[i].push_back(D[i][]);
for(int j = ; j < D[i].size(); j++) Sum[i].push_back(D[i][j]+Sum[i][j-]);
}
while(m--){
scanf("%d %d", &a, &h);
long long d = , n = , decans = ;
int pos1 = upper_bound(D[a].begin(), D[a].end(), h) - D[a].begin();
n += pos1;
decans += getsum(a, , pos1-);
int i = a, j;
while(i != ){
j = i^;
d += v[i/][i&];
if(d < h) {
n++;
decans += d;
}
i /= ;
pos1 = upper_bound(D[j].begin(), D[j].end(), h-v[i][j&]-d) - D[j].begin();
n += pos1;
decans += getsum(j, , pos1-)+pos1*(d+v[i][j&]);
}
long long ans = (long long)n*h - decans;
printf("%lld\n", ans);
}
}

E.就是tarjan缩点+动态规划。

缩点之后可以用dfs直接更新dp。

注意要先求最大值,再加环构成的影响。

求一个边的循环贡献,这里是先排了个序,然后按顺序扫一遍求出来的。

当然也可以二分找。

#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int maxn = 1e6 + ;
stack<int> S;
vector< pair<int, int> > G2[maxn];
vector<int> G[maxn];
long long dp[maxn], v[maxn];
int dfn[maxn], low[maxn], ins[maxn], bl[maxn], C = , Z = ;
int vis[maxn];
void tj(int x)
{
dfn[x]=low[x]=++C; ins[x]=; S.push(x);
for(auto b : G[x])
{
if(!dfn[b]) tj(b),low[x]=min(low[x],low[b]);
else if(ins[b]) low[x]=min(low[x],dfn[b]);
}
if(dfn[x]!=low[x]) return;
++Z;
while(!S.empty())
{
int g=S.top(); S.pop();
ins[g]=; bl[g]=Z;
if(g==x) break;
}
}
struct Edge{
int from, to, cost;
Edge(int from, int to, int cost):from(from), to(to), cost(cost) {}
bool operator <(const Edge &B) const{
return cost < B.cost;
}
};
vector<Edge> edges;
int n, m, x, y, z, s;
long long ans = ;
void dfs(int x){
if(vis[x]) return;
vis[x] = ; dp[x] = ;
for(auto e : G2[x]){
dfs(e.fi);
dp[x] = max(dp[x], dp[e.fi] + e.se);
}
dp[x] += v[x];
ans = max(ans, dp[x]);
}
int main()
{
cin>>n>>m;
for(int i = ; i <= m; i++){
scanf("%d %d %d", &x, &y, &z);
G[x].push_back(y);
edges.push_back(Edge(x, y, z));
}
sort(edges.begin(), edges.end());
cin>>s;
tj(s);
int k = ;
for(auto &e : edges){
while(e.cost >= (k+)*(k+)/) k++;
long long temp = (long long)e.cost*(k+) - (long long)k*(k+)*(k+)/;
if(bl[e.from] == bl[e.to])
v[bl[e.from]] += temp;
else G2[bl[e.from]].push_back(mp(bl[e.to], e.cost));
}
dfs(bl[s]);
cout<<ans<<endl;
return ;
}

Codeforces Round #447 (Div. 2) 题解的更多相关文章

  1. Codeforces Round #447 (Div. 2) 题解 【ABCDE】

    BC都被hack的人生,痛苦. 下面是题解的表演时间: A. QAQ "QAQ" is a word to denote an expression of crying. Imag ...

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  4. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  5. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

随机推荐

  1. Scrapy爬取美女图片续集 (原创)

    上一篇咱们讲解了Scrapy的工作机制和如何使用Scrapy爬取美女图片,而今天接着讲解Scrapy爬取美女图片,不过采取了不同的方式和代码实现,对Scrapy的功能进行更深入的运用.(我的新书< ...

  2. 180723-Quick-Task 动态脚本支持框架之结构设计篇

    文章链接:https://liuyueyi.github.io/hexblog/2018/07/23/180723-Quick-Task-动态脚本支持框架之结构设计篇/ Quick-Task 动态脚本 ...

  3. 180718-jar包执行传参使用小结

    jar包执行时传参的使用姿势 虽说我们现在大多不太直接使用jar包运行方式,目前比较主流的是将自己的服务丢在某个容器中(如tomcat,jetty等)运行,比如我之前所属的电商公司,就是将项目打包为w ...

  4. Wampserver 修改根目录

    wampserver 默认根目录在 www 文件夹下 修改根目录方法如下: 1. 在打算存放项目或代码的位置新建文件夹(我建在了C:/MyProject) 2. 打开 httpd.conf 文件(该文 ...

  5. spring-boot-mybatis搭建

    写在开始 mybatis是一个持久化框架,支持手动sql.存储过程.高级映射.mybatis支持XML方式或注解方式将POJO与数据库表间建立映射. maven依赖 spring-boot.mysql ...

  6. Spring Bean注册解析(一)

           Spring是通过IoC容器对Bean进行管理的,而Bean的初始化主要分为两个过程:Bean的注册和Bean实例化.Bean的注册主要是指Spring通过读取配置文件获取各个bean的 ...

  7. TCP的三次握手(建立连接)和四次挥手(关闭连接)(转)

    转自:(http://www.cnblogs.com/Jessy/p/3535612.html) 参照: http://course.ccniit.com/CSTD/Linux/reference/f ...

  8. ES6的新特性(6)——正则的扩展

    正则的扩展 RegExp 构造函数 在 ES5 中,RegExp构造函数的参数有两种情况. 第一种情况是,参数是字符串,这时第二个参数表示正则表达式的修饰符(flag). var regex = ne ...

  9. centos上搭建git服务--2

    在 Linux 下搭建 Git 服务器   环境: 服务器 CentOS6.6 + git(version 1.7.1)客户端 Windows10 + git(version 2.8.4.window ...

  10. scrum立会报告+燃尽图(第二周第六次)

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2251 一.小组介绍 组名:杨老师粉丝群 组长:乔静玉 组员:吴奕瑶.公冶 ...