zoukankan      html  css  js  c++  java
  • Codeforces Round #485

    B. Petr and Permutations

    大致题意:给出一个1~n的排列,已知该序列是由1,2,3,,,,n随机交换k次数得来,其中(k=3*n)(k=7*n-1)判断该序列是交换多少次得来。

    交换任意两个数会使逆序对个数变化奇数个,而(3*n)(7*n-1)奇偶性不同,因此我们可以直接判断该序列的逆序对个数的奇偶性与(n)的奇偶性是否相同即可。

    (场上我像智障一样打错变量名wa了两发,不然就上黄了。。。)

    #include<bits/stdc++.h>
    #define rre(i,r,l) for(int i=(r);i>=(l);i--)
    #define re(i,l,r) for(int i=(l);i<=(r);i++)
    #define Clear(a,b) memset(a,b,sizeof(a))
    #define inout(x) printf("%d",(x))
    #define douin(x) scanf("%lf",&x)
    #define strin(x) scanf("%s",(x))
    #define op operator
    typedef unsigned long long ULL;
    typedef const int cint;
    typedef long long LL;
    using namespace std;
    template<typename Q>
    void inin(Q &x)
    {
    	x=0;int f=0;char ch=getchar();
    	while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
    	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    	x=f?-x:x;
    }
    int n,a[1000010],b[1000010];
    int ans;
    void guibing(int l,int r)
    {
    	if(l==r)return ;
    	int mid=(l+r)>>1;
    	guibing(l,mid),guibing(mid+1,r);
    	int i=l,j=mid+1,k=l;
    	while(i<=mid&&j<=r)
    	{
    		if(a[i]<=a[j])
    			b[k++]=a[i++];
    		else 
    		{
    			b[k++]=a[j++];
    			ans+=(mid-i+1);
    			ans%=2;
    		}
    	}
    	while(i<=mid)b[k++]=a[i++];
    	while(j<=r)b[k++]=a[j++];
    	for(i=l;i<=r;i++)
    		a[i]=b[i];
    }
    int main()
    {
    	inin(n);
    	re(i,1,n)inin(a[i]);
    	guibing(1,n);
    	int ans1=n%2;
    	int ans2=ans%2;
    	if(ans1==ans2)cout<<"Petr";
    	else cout<<"Um_nik";
    	return 0;
    }
    

    C. AND Graph

    大致题意:给出(n),(m),和(m)个数(x_i<=2^n-1)(x_i)&(x_j=0)则把这两个数连一条无向边,求这(m)个数构成了多少个连通块。

    5个人没有一个人想出来解法,然而这个题就是一手(nlog_2^n)暴搜。。。当然会搜到不属于这m个数的数,这又有什么关系呢?打一手"wocao"标记即可。。。我A掉之后很无语

    #include<bits/stdc++.h>
    #define rre(i,r,l) for(int i=(r);i>=(l);i--)
    #define re(i,l,r) for(int i=(l);i<=(r);i++)
    #define Clear(a,b) memset(a,b,sizeof(a))
    #define inout(x) printf("%d",(x))
    #define douin(x) scanf("%lf",&x)
    #define strin(x) scanf("%s",(x))
    #define op operator
    typedef unsigned long long ULL;
    typedef const int cint;
    typedef long long LL;
    using namespace std;
    template<typename Q>
    void inin(Q &x)
    {
    	x=0;int f=0;char ch=getchar();
    	while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
    	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    	x=f?-x:x;
    }
    int n,bo[5000050],m,a[5000050],wocao[5000050],ans,nn;
    void dfs(int x)
    {
    	if(bo[x])return ;
    	bo[x]=1;
    	if(wocao[x])dfs(nn^x);
    	re(i,0,n)
    		if(x&(1<<i))dfs(x^(1<<i));
    }
    int main()
    {
    	inin(n),inin(m);
    	nn=(1<<n)-1;
    	re(i,1,m)inin(a[i]),wocao[a[i]]=1;
    	re(i,1,m)if(!bo[a[i]])
    	{
    		ans++;
    		dfs(a[i]);
    	}
    	cout<<ans;
    	return 0;
    }
    
  • 相关阅读:
    如何解决错误【selenium.common.exceptions.SessionNotCreatedException】
    VSFTP常用功能及参数配置
    ROS白名单服务端PHP脚本,客户端ROS脚本
    ocserver标准配置文件
    linux send与recv函数详解
    LINUX 恢复rm删除的文件
    C语言实现md5函数代码
    linux c语言获取CPU,内存,网速,磁盘使用,IO
    linux c语言fork socket 并发回射服务器
    杨惠兰不值得任何人付出
  • 原文地址:https://www.cnblogs.com/NoCEinVegetable/p/9112919.html
Copyright © 2011-2022 走看看