A

B

C

注意sum要在mod范围内 且不能用/a*b来推

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll num[];
const ll mod = 1e9 + ;
ll qpow(ll a, ll b)
{
ll ans = , base = a;
while (b)
{
if (b & )
{
ans = (ans * base) % mod;
}
base = (base * base) % mod;
b >>= ;
}
return ans;
}
ll anser = ;
ll sum = ;
ll ok(ll x)
{
return (x % mod + mod) % mod;
}
int main()
{
ll n, a, b, k;
cin >> n >> a >> b >> k;
string str;
cin >> str;
ll now = ;
for (ll i = ; i < k; i++)
{
now = (qpow(a, n - i) * qpow(b, i)) % mod;
if (str[i] == '-')
{
sum = (sum - now + mod) % mod;
}
else
{
sum = (sum + now) % mod;
}
}
ll q = (qpow(b, k) * qpow(qpow(a, mod - ), k)) % mod;
if (q == )
{
cout << (sum * (n + ) / k) % mod << endl;
return ;
}
ll maxn = max(a, b);
ll minn = min(a, b);
ll chu1 = qpow(qpow(a, n + - k), mod - );
ll chu2 = qpow(qpow(maxn, k) - qpow(minn, k), mod - );
chu2 = ok(chu2);
ll beichu = (qpow(maxn, n + ) - qpow(minn, n + )) % mod;
beichu = ok(beichu);
anser = (((((sum * beichu) % mod) * chu1) % mod) * chu2) % mod;
anser = ok(anser);
cout << anser << endl;
}

D

先从叶子节点开始删起 因为如果删除了父亲节点的话 子节点如果是偶数就变成奇数可能会永远删不掉

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = ;
vector<int> tree[];
stack<int> q;
int du[];
int father[];
int visit[];
queue<int> anser;
queue<int> que;
int root;
void dfs(int x, int pre)
{
father[x] = pre;
int len = tree[x].size();
for (int i = ; i < len; i++)
{
int to = tree[x][i];
if (to == pre)
{
continue;
}
dfs(to, x);
}
}
void doit(int x)
{
anser.push(x);
visit[x] = ;
int len = tree[x].size();
for (int i = ; i < len; i++)
{
int to = tree[x][i];
du[to]--;
if (visit[to] || father[x] == to)
{
continue;
}
if (du[to] % == )
{
doit(to);
}
}
}
int main()
{
int n;
cin >> n;
for (int i = ; i <= n; i++)
{
int now;
cin >> now;
if (now == )
{
root = i;
continue;
}
tree[i].push_back(now);
tree[now].push_back(i);
du[i]++, du[now]++;
}
if ((n - ) % )
{
cout << "NO" << endl;
return ;
}
dfs(root, );
que.push(root);
while (!que.empty())
{
int x = que.front();
que.pop();
q.push(x);
int len = tree[x].size();
for (int i = ; i < len; i++)
{
int to = tree[x][i];
if (to == father[x])
{
continue;
}
que.push(to);
}
}
while (!q.empty())
{
if (du[q.top()] % == )
{
doit(q.top());
}
q.pop();
}
if (anser.size() != n)
{
cout << "NO" << endl;
return ;
}
cout << "YES" << endl;
while (!anser.empty())
{
cout << anser.front() << endl;
anser.pop();
}
}

Codeforces 964 等比数列逆元处理 贪心删偶数度节点的更多相关文章

  1. Codeforces 346C Number Transformation II 贪心(复杂度计算)

    题意及思路:https://www.cnblogs.com/liuzhanshan/p/6560499.html 这个做法的复杂度看似是O(n ^ 2),实际上均摊是O(n)的.我们考虑两种极端数据: ...

  2. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  3. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  4. Codeforces 963E Alternating Sum 等比数列+逆元

    题目大意: 看一下样例就明白了 基本思路: 题目中明确提到k为一个周期,稍作思考,把k项看作一项,然后发现这是个等比数列,q=(b/a)^k, 然后重点就是怎样处理等比数列求和表达式中的除法,这个时候 ...

  5. Codeforces 798D Mike and distribution - 贪心

    Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...

  6. Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】

    B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...

  7. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  8. Codeforces Gym 100269E Energy Tycoon 贪心

    题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...

  9. CodeForces 797C Minimal string:贪心+模拟

    题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...

随机推荐

  1. MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications

    1. 摘要 作者提出了一系列应用于移动和嵌入式视觉的称之为 MobileNets 的高效模型,这些模型采用深度可分离卷积来构建轻量级网络. 作者还引入了两个简单的全局超参数来有效地权衡时延和准确率,以 ...

  2. 10 mysql选错索引

    10 mysql选错索引 在mysql表中可以支持多个索引,有的sql不指定使用哪个索引,由mysql自己来决定,但是有时候mysql选错了索引,导致执行很慢. 例子 CREATE TABLE `t1 ...

  3. unieap platform eclipse.ini vm设置

    -vm C:\Program Files (x86)\Java\jdk1..0_45\bin\javaw.exe -startup plugins/org.eclipse.equinox.launch ...

  4. 重叠IO 模型

    1. 重叠模型的优点 2. 重叠模型的基本原理 3. 关于重叠模型的基础知识 4. 重叠模型的实现步骤 5. 多客户端情况的注意事项 一.重叠模型的优点   1.可以运行在支持Winsock2的所有W ...

  5. Docker】如何修改Docker的默认镜像存储位置

    江湖有多大,坑就有多多……我使用的服务器, 系统盘根目录只有20G, 默认Docker 的镜像文件是安装在/var/lib/docker 目录下的, 这样的话我根本装不了太多的镜像,之前遇到一种情况就 ...

  6. 【VS开发】【图像处理】相机中白平衡的算法模拟实现

    相机主要技术点为3A算法. 而3A算法主要指的是自动对焦(AF).自动曝光(AE)及自动白平衡(AWB).自动白平衡:根据光源条件调整图片颜色的保真程度. 网上时常有类似招聘如下的招聘信息: ---- ...

  7. 微信小程序 解析html格式内容

    需要引入html-view文件 1/js 代码 const HtmlParser=require('../../utils/html-view/index') data: { coupon_text: ...

  8. 交换机安全学习笔记 第八章 针对POE的攻击

    POE即 Power over Ethernet 借助于以太网供电.最初为了IP电话,目前主要用于功耗小于15.4w的设备例如Ap和视频监控设备.并且简化了相关设备的电力线布线. 英文缩写注释:PSE ...

  9. Elasticsearch-安装、日志解读

    ES-安装.日志解读 1. 准备tar包 https://www.elastic.co/cn/products/elasticsearch2. 解压 tar -zxvf elasticsearch-. ...

  10. spring boot-10.国际化

    1.在原来spring MVC 中国际化实现步骤 (1)编写国际化配置文件 (2)使用ResourceBundleMessageSource管理国际化资源文件 (3)在页面中取国际化信息 2.spri ...