2018徐州现场赛A

题目链接:http://codeforces.com/gym/102012/problem/A

题目给出的算法是通过异或和位移 , 每次生成不同的32位, 周期为2的32次方减1。题目的总边数太少,跑不出重边,所以有最小生成树的话就只有一个

#include<iostream>
#include<algorithm>
using namespace std;
unsigned long long k1,k2;
#define inf 0x3f3f3f3f
#define mod 1000000007
int tot;
unsigned long long xo()
{
    unsigned long long k3=k1,k4=k2;
    k1=k4;
    k3^=k3<<23;
    k2=k3^k4^(k3>>17)^(k4>>26);
    return k2+k4;
}
struct edge{
    int u,v;
    unsigned long long w;
    bool operator <(const edge &a)const{
        return w<a.w;
    }
}e[100010];
int n,m,fa[100010],cnt;
unsigned long long ans;
void add(int u,int v,unsigned long long w)
{
    e[++cnt].u=u;
    e[cnt].v=v;
    e[cnt].w=w;
}
void gen()
{
    int u,v;
    unsigned long long w;
    scanf("%d%d%llu%llu",&n,&m,&k1,&k2);
    cnt=0;
    for(int i=1;i<=m;i++)
    {
        u=xo()%n+1;
        v=xo()%n+1;
        w=xo();
        add(u,v,w);
    }
}
int _find(int u)
{
    if(fa[u]==u)return u;
    return fa[u]=_find(fa[u]);//路径压缩
}
unsigned long long solve()
{
    tot=1;
    sort(e+1,e+1+cnt);
    int u,v,x,y;
    unsigned long long w;
    ans=0;
    for(int i=1;i<=n;i++)
    fa[i]=i;
    for(int i=1;i<=cnt;i++)
    {
        u=e[i].u;v=e[i].v;w=e[i].w;
        x=_find(u);y=_find(v);
        if(x!=y)
        {
            ans=(ans+w)%mod;
            tot++;
            fa[y]=x;
            if(tot==n)return ans;
        }
    }
    return 0;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        gen();
        ans=inf;
        printf("%llu\n",solve());
    }
    return 0;
}

原文地址:https://www.cnblogs.com/chen99/p/11707579.html

时间: 2024-11-02 08:13:38

2018徐州现场赛A的相关文章

2018徐州网络赛H. Ryuji doesn&#39;t want to study

题目链接: https://nanti.jisuanke.com/t/31458 题解: 建立两个树状数组,第一个是,a[1]*n+a[2]*(n-1)....+a[n]*1;第二个是正常的a[1],a[2],a[3]...a[n] #include "bits/stdc++.h" using namespace std; #define ll long long const int MAXN=1e5+10; ll sum[MAXN],ans[MAXN]; ll num[MAXN];

ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn&#39;t want to study

C*M....死于update的一个long long写成int了 心累 不想写过程了 ******** 树状数组,一个平的一个斜着的,怎么斜都行 题库链接:https://nanti.jisuanke.com/t/31460 #include <iostream> #include <cstring> #define ll long long #define lowbit(x) (x & -x) using namespace std; const int maxn =

2018 徐州网络赛 H

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That means, if he reads books from ll to rr, he will get a

2018 徐州网络赛A

262144K After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked Kokoro to deliver a Nogaku show during the feast. To enjoy the show, every audience has to wear a Nogaku mask, and seat around as a circle. There are N guests Re

2018 徐州网络赛 J

131072K After the long vacation, the maze designer master has to do his job. A tour company gives him a map which is a rectangle. The map consists of N \times MN×M little squares. That is to say, the height of the rectangle is NN and the width of the

【2018沈阳现场赛k】Let the Flames Begin

题意 有n个人围成一圈,编号1到n,从1号开始报数,每报到第k个,此人出列,下一个人再从1开始报数,求第m个出列的人的编号(n,m,k ≤ 1e18, m,k其中一个小于1e6) 分析 我们知道,约瑟夫环的出队是有O(n)的递推算法的:f(n) = (f(n-1)+k-1)%n 约瑟夫环数学推导 但是这里是最后一个出列的人的情况(n个人第n个出列) 考虑一下n个人第m个出列,设状态为f(n,m),我们可以假设在m个人中再插上n-m个人,他们都比前m个人晚出队(具体放在哪里不用关心,只要认为他们一

【2018徐州网络赛】Morgana Net (矩阵快速幂)

给你一个n*n的矩阵A,和一个m*m的矩阵B(m%2==1) B是卷积核,让你用B对A做t次卷积运算,并且对于A中的每一个元素计算出来的值要模2,所以A最后会是一个01矩阵. 问你经过t此后,A中有多少个元素=1 1<=t<=1e9,1<=n<=8,1<=m<=n SOLUTION: 二维矩阵展成1维 那么做法就是把A矩阵变成一个1*(n*n)的一维向量,然后构造一个(n*n)*(n*n)的辅助矩阵 我们观察到对于A中的每一个元素,每一次卷积运算,所要求乘积的值的位置是

2018南京现场赛K 随机输出

题目链接:http://codeforces.com/gym/101981/attachments n和m太小,空地联通无环,总步数太大,直接随机输出5w个方向 #include<iostream> #include<algorithm> #include<ctime> using namespace std; int t,a,b,c,d,k; int main() { srand((unsigned)time(0)); int n,m; char op,ch[4]={

2020年2月2日 ICPC2019徐州 现场赛C &lt;3 numbers 思维题

问因数<3的数个数,是否小于给定区间1/3.因数<3除了1以外等价于素数. 据说杜教筛改成求素数前缀和的版本可以暴力做,但是并不会. 我们一个直观感受是,素数是越来越稀疏的,打表发现,50以外长度30以上,一定满足.而长度不到30的,用根号算法暴力判断每个元素即可. 注意要以乘代除,或者起码除double...... 1 #include <cstdio> 2 #include <cmath> 3 using namespace std; 4 int T,l,r; 5