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;}
//head const 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. 骨牌覆盖

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

Wannafly挑战赛22的更多相关文章

  1. Wannafly挑战赛22游记

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

  2. Wannafly挑战赛 22

    爆零祭 T1 这题第一反应gcd啊 所以就把每个a[i]对m取模 然后求它们的gcd 即res = gcd(a[1] % m, a[2] % m, ... , a[n] % m) ans = 1 + ...

  3. Wannafly 挑战赛22 D 整数序列 线段树 区间更新,区间查询

    题目链接:https://www.nowcoder.com/acm/contest/160/D 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言524288K ...

  4. 多项式 Wannafly挑战赛22

    后缀表达式 大整数(加法.乘法.gcd java) import java.math.BigInteger; import java.util.Scanner; class Work { String ...

  5. Wannafly挑战赛22 A-计数器(gcd,裴蜀定理)

    原题地址 题目描述 有一个计数器,计数器的初始值为0,每次操作你可以把计数器的值加上a1,a2,...,an中的任意一个整数,操作次数不限(可以为0次),问计数器的值对m取模后有几种可能. 输入描述: ...

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

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

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

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

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

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

  9. Wannafly挑战赛13 zzf的好矩阵 题解 答案解释

    Wannafly挑战赛13 zzf的好矩阵 题解 文章目录 Wannafly挑战赛13 zzf的好矩阵 题解 分析 结论1 结论2 结论3 C数组对应带子说明 空白长度论述 后续黑色长度论述 能&qu ...

随机推荐

  1. Ryu控制器编程开发——packet_in和packet_out简易交换机实现

    Ryu控制器二次开发,实现一个简单的只能够简单地广播数据包的交换机. from ryu.base import app_manager from ryu.controller import ofp_e ...

  2. csp-s模拟106

    这场其实心态十分爆炸,首先一下午改上次破T3卡常一下午没过,心情十分暴躁.上来开题不顺利,T1想了一个小时没动.于是跳到T2,看T2的80pts貌似可拿就先打了.T3只会判10分,又想打个$2^{2N ...

  3. Build Telemetry for Distributed Services之Open Telemetry来历

    官网:https://opentelemetry.io/ github:https://github.com/open-telemetry/ Effective observability requi ...

  4. django安装xadmin中出现的报错汇总

    报错一:ModuleNotFoundError: No module named 'django.core.urlresolvers' ModuleNotFoundError: No module n ...

  5. 关于Jmeter测试移动端应用时提示非法登录,不是合法的登录设备时的解决办法

    当Jmeter测试移动端应用时提示非法登录,不是合法的登录设备时的解决办法:只需要在jmeter的http信息头管理器中配置相应的设备信息,可通过抓包工具得到:即头信息Header中的Miscella ...

  6. MATLAB常用快捷键总结

    MATLAB 命令栏显示处理的常用命令 清屏:clc 紧凑显示格式:format compact 宽松显示格式:format loose 数据高精度显示:format longG 数据低精度显示:fo ...

  7. JAVA 基础编程练习题46 【程序 46 字符串连接】

    46 [程序 46 字符串连接] 题目:两个字符串连接程序 package cskaoyan; public class cskaoyan46 { public static void main(St ...

  8. React Native init初始化项目时报错

    之前新建RN项目都不会出现这个问题,今天报错如下,这里记录下吧. 报错截图: This will walk you through creating a new React Native projec ...

  9. Android view的一些认识

    转载:9102年末,我对Android view的13条认识: (顺手留下GitHub链接,需要获取相关面试等内容的可以自己去找)https://github.com/xiangjiana/Andro ...

  10. 【从零开始搭建K8S】【第一篇】CentOS7.6离线安装Docker(手动安装以及基于yum本地源安装)

    下载CentOS7.6以及最小化安装CentOS7.6版本.由于CentOS属于开源软件,在国内也有很多的mirror站点可供下载,我选择的是华为站点进行下载:http://mirrors.huawe ...