摘要: 这道题我最开始是想着用dfs的但一看数据量肯定会超时,看了视频才发现可以用spfa,虽然是无权图,但我们可以把边权看作一,我们只需要记录到1的最短距离,如果vc[u][i].dis+w[u]==w[v]那就cnt[v]=(cnt[v]+cnt[u])%100003;如果遇到vc[u][i].dis+ 阅读全文
posted @ 2025-02-19 15:42 郭轩均 阅读(27) 评论(0) 推荐(0)
摘要: 由于题目没有说是连通图,所以最开始时要把所有点加入队列 #include<iostream> #include<queue> #include<vector> using namespace std; struct node { int id; int dis; }; const int N=5*1 阅读全文
posted @ 2025-02-19 14:42 郭轩均 阅读(30) 评论(0) 推荐(0)
摘要: 这道题要用floyd算法,如果a可以战胜b,b可以战胜c,那么a可以战胜c,并且这道题的数据范围很小,首先遍历第i头奶牛可以战胜几头奶牛,然后再统计有几头奶牛可以战胜它,如果加起来等于n-1,说明它与其它所有的奶牛的关系都确定了, #include<iostream> using namespace 阅读全文
posted @ 2025-02-19 14:11 郭轩均 阅读(28) 评论(0) 推荐(0)
摘要: 如果1可以变换到2,2可以变换到3,那么1可以变换到3,这可以用Floyd算法,要注意一点的是,其它数不可以变换到零,而零可以变到其它数, 我的高精度算法一开始是错的,我的做法会导致进位的数也乘了s,在最后要处理carry,但要记得carry/10,不然会成死循环 #include<iostream 阅读全文
posted @ 2025-02-18 22:30 郭轩均 阅读(16) 评论(0) 推荐(0)
摘要: #include<iostream> using namespace std; int d[120][120]; int w[10020]; int main(){ int n,m; cin>>n>>m; for(int i=1;i<=m;i++)cin>>w[i]; for(int i=1;i<= 阅读全文
posted @ 2025-02-18 20:28 郭轩均 阅读(12) 评论(0) 推荐(0)
摘要: 这道题要注意初始化w数组为最大值,并且w[1]=0;有负环的话输出YES,没有输出NO; #include<iostream> #include<queue> #include<vector> using namespace std; const int N=3000+5; struct node{ 阅读全文
posted @ 2025-02-18 20:13 郭轩均 阅读(10) 评论(0) 推荐(0)
摘要: 迪杰斯特拉算法就是每次寻找与与原点最近的点然后更新与它相连的点,要注意的是传入起始点时不需要标记它,因为需要它扩展到其他点,只有当一个点出队时才需要标记它,因为后入队的同一个点可能距离更小 #include<iostream> #include<queue> #include<vector> #de 阅读全文
posted @ 2025-02-18 20:10 郭轩均 阅读(12) 评论(0) 推荐(0)
摘要: 这道题,没想到可以把启动机器时间对后面的影响分离出来,这样第i个物品处理完的时间就是处理前面i个物品的时间总和 #include<iostream> #define int long long using namespace std; const int N=1e6; int f[N]; int c 阅读全文
posted @ 2025-02-18 15:19 郭轩均 阅读(8) 评论(0) 推荐(0)
摘要: 注意不要把q[h+1]写成q[h-1]; #include<iostream> using namespace std; #define int long long const int N=4*1e6+200; int f[N]; int s[N]; int c[N]; int q[N]; doub 阅读全文
posted @ 2025-02-18 14:33 郭轩均 阅读(17) 评论(0) 推荐(0)
摘要: 斜率优化dp最重要的就是写正确关系式并且找对x,y,k,b; f[i]=f[j]+(i-(j+1)+sum[i]-sum[j+1-1]-l)^2 减的是j+1,因为求的是j+1到i; f[i]=f[j]+(s[i]+i-(s[j]+j)-(l+1))^2; 令pi=s[i]+i,pj=s[j]+j, 阅读全文
posted @ 2025-02-18 13:53 郭轩均 阅读(16) 评论(0) 推荐(0)