B. 字符路径

给一个含n个点m条边的有向无环图(允许重边,点用1到n的整数表示),每条边上有一个字符,问图上有几条路径满足路径上经过的边上的字符组成的的字符串去掉空格后以大写字母开头,句号 '.' 结尾,中间都是小写字母,小写字母可以为0个。

dp[x][0]为全空格的方案, dp[x][1]为空格加字母的方案, dp[x][2]为合法路径数.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, P2 = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//headconst int N = 1e6+10;
int n, m, deg[N], dp[N][3];
struct _ {int to;char w;};
vector<_> g[N];
queue<int> q;int main() {scanf("%d%d", &n, &m);REP(i,1,m) {int u, v;char w;scanf("%d%d %c", &u, &v, &w);g[u].pb({v,w});++deg[v];}REP(i,1,n) if (!deg[i]) q.push(i);unsigned ans = 0;while (q.size()) {int u = q.front(); q.pop();ans += dp[u][2];for (_ e:g[u]) {int v = e.to;if (isupper(e.w)) {dp[v][1] += dp[u][0]+1;}else if (islower(e.w)) {   dp[v][1] += dp[u][1];}else if (e.w=='_') {dp[v][0] += dp[u][0]+1;dp[v][1] += dp[u][1];dp[v][2] += dp[u][2];}else if (e.w=='.') {dp[v][2] += dp[u][1];}if (!--deg[v]) q.push(v);}}printf("%u\n", ans);
}

D.整数序列

大意: 区间加, 求区间sin和.

线段树维护, 注意爆int

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
const int N = 2e5+10;
int n, m, a[N];
struct _ {double c, s;ll tag;void upd(int x) {tie(c,s) = pair<double,double>(c*cos(x)-s*sin(x),c*sin(x)+s*cos(x));      tag += x;}_ operator + (const _ & rhs) const {return {c+rhs.c,s+rhs.s,0ll};}
} tr[N<<2];void pd(int o) {if (tr[o].tag) {tr[lc].upd(tr[o].tag),tr[rc].upd(tr[o].tag);tr[o].tag = 0;}
}
void build(int o, int l, int r) {if (l==r) tr[o]={cos(a[l]),sin(a[l]),0ll};else build(ls),build(rs),tr[o]=tr[lc]+tr[rc];
}
void update(int o, int l, int r, int ql, int qr, int v) { if (ql<=l&&r<=qr) return tr[o].upd(v);pd(o);if (mid>=ql) update(ls,ql,qr,v);if (mid<qr) update(rs,ql,qr,v);tr[o]=tr[lc]+tr[rc];
}
double query(int o, int l, int r, int ql, int qr) {if (ql<=l&&r<=qr) return tr[o].s;pd(o);double ans = 0;if (mid>=ql) ans += query(ls,ql,qr);if (mid<qr) ans += query(rs,ql,qr);return ans;
}int main() {scanf("%d", &n);REP(i,1,n) scanf("%d", a+i);build(1,1,n);scanf("%d", &m);while (m--) {int op,l,r,v;scanf("%d%d%d",&op,&l,&r);if (op==1) {scanf("%d", &v);update(1,1,n,l,r,v);}else if (op==2) printf("%.1lf\n", query(1,1,n,l,r));}
}

E. 骨牌覆盖

给定棋盘, 一些格子有挡板, 求骨牌摆放方案数.

转载于:https://www.cnblogs.com/uid001/p/10971022.html

Wannafly挑战赛22相关推荐

  1. Wannafly挑战赛22游记

    Wannafly挑战赛22游记 幸运的人都是相似的,不幸的人各有各的不幸. --题记 A-计数器 题目大意: 有一个计数器,计数器的初始值为\(0\),每次操作你可以把计数器的值加上\(a_1,a_2 ...

  2. Wannafly挑战赛22 C 多项式(大数,多项式极限)

    链接:https://ac.nowcoder.com/acm/contest/160/C 来源:牛客网 多项式 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言 ...

  3. Wannafly挑战赛22 D 整数序列 (线段树维护三角函数值)

    链接:https://ac.nowcoder.com/acm/contest/160/D 来源:牛客网 整数序列 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语 ...

  4. Wannafly挑战赛22 B 字符路径 ( 拓扑排序+dp )

    链接:https://ac.nowcoder.com/acm/contest/160/B 来源:牛客网 题目描述 给一个含n个点m条边的有向无环图(允许重边,点用1到n的整数表示),每条边上有一个字符 ...

  5. Wannafly挑战赛22: C. 多项式(大整数)

    题目描述 求,其中f和g是关于x的多项式. 输入描述: 两行,第一行为f,第二行为g. f和g都用一个由小括号 '(' 和 ')' .加号 '+' .乘号 '*' . 'x' 组成的表达式表示,表达式 ...

  6. Wannafly挑战赛22:B. 字符路径

    题目描述 给一个含n个点m条边的有向无环图(允许重边,点用1到n的整数表示),每条边上有一个字符,问图上有几条路径满足路径上经过的边上的字符组成的的字符串去掉空格后以大写字母开头,句号 '.' 结尾, ...

  7. Wannafly挑战赛22 D-整数序列 (线段树)

    https://www.nowcoder.com/acm/contest/160/D 做法:用线段树维护,对于树上的每个叶子结点,维护一个复数结构体 cos(a[i] + sin(a[i])*i ,每 ...

  8. [Wannafly挑战赛2D-Delete]最短路

    [Wannafly挑战赛2D-Delete]最短路 题目描述 给定一张 n 个点,m 条边的带权有向无环图,同时给定起点 S 和终点 T ,一共有 q 个询问,每次询问删掉某个点和所有与它相连的边之后 ...

  9. Wannafly挑战赛19

    Wannafly挑战赛19 A. 队列Q 需要支持把一个元素移到队首,把一个元素移到队尾,移到队首就直接放到队首前面那个位置,原位置标为0,队尾同理. #include <bits/stdc++ ...

最新文章

  1. 将公用文件夹从Exchange2010迁移到 Exchange 2013
  2. JSP页面和产品明细页面的绑定关系在Hybris WCMS cockpit什么地方能够找到
  3. 使用PDFBox解析PDF文件
  4. oracle将一个表数据更新时间,Oracle批量更新,将一个表的数据批量更新另一表
  5. PHP程序构造,PHP程序员在做网站开发前对基本目录结构如何规划?
  6. 泵车砼活塞故障预警-冠军方案
  7. Common Lisp之Slime函数调用快捷键(三)
  8. unity 控制人物模型移动
  9. VS2015自定义编程背景
  10. 【老生谈算法】matlabBOOST电路的设计与仿真——BOOST电路
  11. 自适应函数符和函数适配器(Adaptable Functors and Function Adapters)
  12. Oracle LOB
  13. WinEdit编辑器中中文乱码
  14. Rust 编译模型之殇
  15. ECharts 区域缩放组件使用详解
  16. 如何利用手机进行英语学习?
  17. 第四篇:mmpose之各类Demo测试及自定义数据原理(强推)
  18. 【保研】-- 保研夏令营中英语口语技巧问题
  19. lua管理linux,Linux 安装 luarocks(lua的模块管理工具)
  20. android使用自己定义属性AttributeSet

热门文章

  1. Java的知识点16——数组概述和特点、数组声明、初始化、数组的遍历、for-each循环、数组的拷贝
  2. 将格式化的日期字符串转换为Unix时间戳(php)
  3. Python 技术篇-利用pyqt5库监听剪切板变动,clipboard.dataChanged.connect()剪切板监听
  4. DbVisualizer数据库连接工具默认查询结果只显示100条解决方法,dbvis如何展示更多行,如何显示全部数据
  5. leetCode C++ 二分查找 35. 搜索插入位置 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。
  6. [YTU]_2444( C++习题 对象转换)
  7. 常见b2c网站购物车的设计
  8. LCD编程_LCD控制器
  9. javascript 数组和对象的浅复制和深度复制 assign/slice/concat/JSON.parse(JSON.stringify())...
  10. Python3入门(十一)——IO编程