Wannafly挑战赛22游记
Wannafly挑战赛22游记
幸运的人都是相似的,不幸的人各有各的不幸。
——题记
A-计数器
题目大意:
有一个计数器,计数器的初始值为\(0\),每次操作你可以把计数器的值加上\(a_1,a_2,\ldots,a_n\)中的任意一个整数,操作次数不限(可以为\(0\)次),问计数器的值对\(m\)取模后有几种可能。
思路:
由裴蜀定理易得,答案即为\(\frac m{\gcd(m,a_1,a_2,\ldots,a_n)}\)。
源代码:
#include<cstdio>
#include<cctype>
#include<algorithm>
inline int getint() {register char ch;while(!isdigit(ch=getchar()));register int x=ch^'0';while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');return x;
}
const int N=101;
int a[N];
int main() {const int n=getint(),m=getint();int gcd=m;for(register int i=1;i<=n;i++) {a[i]=getint()%m;gcd=std::__gcd(gcd,a[i]);}printf("%d\n",m/gcd);return 0;
}
B-字符路径
题目大意:
给一个含\(n\)个点\(m\)条边的有向无环图(允许重边,点用\(1\)到\(n\)的整数表示),每条边上有一个字符,问图上有几条路径满足路径上经过的边上的字符组成的的字符串去掉空格后以大写字母开头,句号'.'
结尾,中间都是小写字母,小写字母可以为\(0\)个。
思路:
拓扑序上DP,记录每个点可以对应多少个大写字母开头的字符串,若在前面加上空格有多少种方案,在后面加上空格有多少种方案(反图)。若当前边为'.'
则计算对答案的贡献。
源代码:
#include<queue>
#include<cstdio>
#include<cctype>
#include<vector>
inline int getint() {register char ch;while(!isdigit(ch=getchar()));register int x=ch^'0';while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');return x;
}
inline int getch() {register char ch=getchar();while(!isalpha(ch)&&ch!='_'&&ch!='.') ch=getchar();return ch;
}
const int N=5e4+1;
struct Edge {int to;char w;
};
std::vector<Edge> e[N],e2[N];
inline void add_edge(const int &u,const int &v,const char &w) {e[u].push_back((Edge){v,w});
}
inline void add_edge2(const int &u,const int &v,const char &w) {e2[u].push_back((Edge){v,w});
}
int n,m,ind[N],outd[N];
unsigned upper[N],space[N],space2[N],ans;
std::queue<int> q;
void kahn2() {for(register int i=1;i<=n;i++) {if(outd[i]==0) q.push(i);}while(!q.empty()) {const int &x=q.front();for(auto &j:e2[x]) {const int &y=j.to;const char &w=j.w;if(w=='_') space2[y]+=space2[x]+1;if(!--outd[y]) q.push(y);}q.pop();}
}
void kahn() {for(register int i=1;i<=n;i++) {if(ind[i]==0) q.push(i);}while(!q.empty()) {const int &x=q.front();for(auto &j:e[x]) {const int &y=j.to;const char &w=j.w;if(isupper(w)) upper[y]+=space[x]+1;if(islower(w)) upper[y]+=upper[x];if(w=='_') {space[y]+=space[x]+1;upper[y]+=upper[x];}if(w=='.') ans+=upper[x]*(space2[y]+1);if(!--ind[y]) q.push(y);}q.pop();}
}
int main() {n=getint(),m=getint();for(register int i=0;i<m;i++) {const int u=getint(),v=getint();const char w=getch();add_edge(u,v,w);add_edge2(v,u,w);ind[v]++;outd[u]++;}kahn2();kahn();printf("%u\n",ans);return 0;
}
D-整数序列
题目大意:
给出一个长度为\(n\)的整数序列\(a_1,a_2,\ldots,a_n\),进行\(m\)次操作,操作分为两类:
- 给出\(l,r,v\),将\(a_{l\sim r}\)分别加上\(v\);
- 给出\(l,r\),询问\(\sum_{i=l}^r\sin(a_i)\)。
思路:
根据三角恒等变换:
\[ \begin{align*} \sin(\alpha+\beta)=\sin\alpha\cdot\cos\beta+\cos\alpha\cdot\sin\beta\\ \cos(\alpha+\beta)=\cos\alpha\cdot\cos\beta-\sin\alpha\cdot\sin\beta \end{align*} \]
用线段树维护区间\(\sum\sin(a_i)\)和区间\(\sum\cos(a_i)\)即可。
考虑写成复数的形式,\(\cos\)作为实部,\(\sin\)作为虚部。使用std::complex
可以很方便的维护。
源代码:
#include<cmath>
#include<cstdio>
#include<cctype>
#include<complex>
#include<algorithm>
inline int getint() {register char ch;while(!isdigit(ch=getchar()));register int x=ch^'0';while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');return x;
}
typedef long long int64;
typedef std::complex<double> comp;
const int N=2e5+1;
class SegmentTree {#define _left <<1#define _right <<1|1#define mid ((b+e)>>1)private:comp val[N<<2],tag[N<<2];void push_up(const int &p) {val[p]=val[p _left]+val[p _right];}void push_down(const int &p) {if(tag[p]==comp(1,0)) return;val[p _left]*=tag[p];val[p _right]*=tag[p];tag[p _left]*=tag[p];tag[p _right]*=tag[p];tag[p]=comp(1,0);}public:void build(const int &p,const int &b,const int &e) {if(b==e) {const int x=getint();val[p]=comp(cos(x),sin(x));return;}tag[p]=comp(1,0);build(p _left,b,mid);build(p _right,mid+1,e);push_up(p);}void modify(const int &p,const int &b,const int &e,const int &l,const int &r,const comp &x) {if(b==l&&e==r) {tag[p]*=x;val[p]*=x;return;}push_down(p);if(l<=mid) modify(p _left,b,mid,l,std::min(mid,r),x);if(r>mid) modify(p _right,mid+1,e,std::max(mid+1,l),r,x);push_up(p);}double query(const int &p,const int &b,const int &e,const int &l,const int &r) {if(b==l&&e==r) return val[p].imag();push_down(p);double ret=0;if(l<=mid) ret+=query(p _left,b,mid,l,std::min(mid,r));if(r>mid) ret+=query(p _right,mid+1,e,std::max(mid+1,l),r);return ret;}#undef _left#undef _right#undef mid
};
SegmentTree t;
int main() {const int n=getint();t.build(1,1,n);const int m=getint();for(register int i=0;i<m;i++) {const int opt=getint(),l=getint(),r=getint();if(opt==1) {const int x=getint();t.modify(1,1,n,l,r,comp(cos(x),sin(x)));}if(opt==2) {printf("%.1f\n",t.query(1,1,n,l,r));}}return 0;
}
转载于:https://www.cnblogs.com/skylee03/p/9495843.html
Wannafly挑战赛22游记相关推荐
- Wannafly挑战赛22
B. 字符路径 给一个含n个点m条边的有向无环图(允许重边,点用1到n的整数表示),每条边上有一个字符,问图上有几条路径满足路径上经过的边上的字符组成的的字符串去掉空格后以大写字母开头,句号 '.' ...
- Wannafly挑战赛22 C 多项式(大数,多项式极限)
链接:https://ac.nowcoder.com/acm/contest/160/C 来源:牛客网 多项式 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言 ...
- Wannafly挑战赛22 D 整数序列 (线段树维护三角函数值)
链接:https://ac.nowcoder.com/acm/contest/160/D 来源:牛客网 整数序列 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语 ...
- Wannafly挑战赛22 B 字符路径 ( 拓扑排序+dp )
链接:https://ac.nowcoder.com/acm/contest/160/B 来源:牛客网 题目描述 给一个含n个点m条边的有向无环图(允许重边,点用1到n的整数表示),每条边上有一个字符 ...
- Wannafly挑战赛22: C. 多项式(大整数)
题目描述 求,其中f和g是关于x的多项式. 输入描述: 两行,第一行为f,第二行为g. f和g都用一个由小括号 '(' 和 ')' .加号 '+' .乘号 '*' . 'x' 组成的表达式表示,表达式 ...
- Wannafly挑战赛22:B. 字符路径
题目描述 给一个含n个点m条边的有向无环图(允许重边,点用1到n的整数表示),每条边上有一个字符,问图上有几条路径满足路径上经过的边上的字符组成的的字符串去掉空格后以大写字母开头,句号 '.' 结尾, ...
- Wannafly挑战赛22 D-整数序列 (线段树)
https://www.nowcoder.com/acm/contest/160/D 做法:用线段树维护,对于树上的每个叶子结点,维护一个复数结构体 cos(a[i] + sin(a[i])*i ,每 ...
- [Wannafly挑战赛2D-Delete]最短路
[Wannafly挑战赛2D-Delete]最短路 题目描述 给定一张 n 个点,m 条边的带权有向无环图,同时给定起点 S 和终点 T ,一共有 q 个询问,每次询问删掉某个点和所有与它相连的边之后 ...
- Wannafly挑战赛19
Wannafly挑战赛19 A. 队列Q 需要支持把一个元素移到队首,把一个元素移到队尾,移到队首就直接放到队首前面那个位置,原位置标为0,队尾同理. #include <bits/stdc++ ...
最新文章
- android的UI开发工程师指引
- Windows Phone 7 页面的数值传递和对象传递
- CentOS 7 内存压力测试-memtester工具
- logstash使用中遇到的问题
- python文本清洗_【python】TXT文本数据清洗和英文分词、词性标注
- jenkins 插件目录_三十二张图告诉你如何用Jenkins构建SpringBoot
- Chapter7-9_Deep Learning for Dependency Parsing
- 牛刀小试:使用Reactive Extensions(Rx),对短时间内多次发生的事件限流
- hnu 暑期实训之相同生日
- 软件测试培训班出来好找工作么
- 国内外AI绘画『文生图』大模型效果对比
- HTML如何实现多个空格
- CentOS7中使用kubeadm快速部署一套K8S集群
- Apache Kafka API AdminClient Scram账户的操作(增删改查)
- 使用切图工具经常遇到的问题
- 财经365视界:韩国新首富“脚踩三星”
- web前端期末大作业:个人网站设计——响应式个人小站网站HTML+CSS+JavaScript
- 【go】网络编程-HTTP编程
- 使用深度神经网络完成对鸢尾花的分类
- 【mini2440】U-boot
热门文章
- python pandas读取txt文件_python Pandas 读取txt表格的实例
- 关于错误	1	error C4996: 'getch': The POSIX name for this item is deprecated.问题解决方式
- 2021河北省高考成绩查询步骤,河北省2021年普通高校招生考试和录取工作实施方案解读...
- Java实现K-means
- On Tutorial with Caffe--a Hands DIY DL for Vision
- 在电脑桌面 右键点击 计算机,在桌面上右键点击电脑
- (上)挖掘传统行业日志大数据的无限价值
- 通过js 判断当前应用是什么浏览器【借鉴转载】
- 8. Python 数据类型
- 互联网通用架构技术----缓存雪崩