SEERC 2018 H - Modern Djinn (随机化)

简介: SEERC 2018 H - Modern Djinn (随机化)

linkkkkk

题意:

有n个人,每个人的属性值为0或1;m个愿望,x − > y,如果一个愿望被满足的话,说明x的属性值为1,y的属性值为0。要求至少满足m / 4 + 1愿望,输出方案数。

思路:

对于每一个愿望,都有4种方案,只有一种是正确的,概率为1/4

随机赋值0 / 1的话,大概有m / 4个愿望被满足。

跑得飞快。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;typedef unsigned long long ull;
typedef pair<ll,ll>PLL;typedef pair<int,int>PII;typedef pair<double,double>PDD;
#define I_int ll
inline ll read(){ll x=0,f=1;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();}return x*f;}
#define read read()
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define dep(i, a, b) for(int i=(a);i>=(b);--i)
ll ksm(ll a,ll b,ll p){ll res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
const int maxn=2e5+7,maxm=1e6+7,mod=1e9+7;
int x[maxn],y[maxn],a[maxn];
int main(){
  srand(time(0));
  int _=read;
  while(_--){
    int n=read,m=read;
    for(int i=1;i<=m;i++){
      x[i]=read,y[i]=read;
    }
    int sum=m/4+1,now=0;
    while(1){
      now=0;
      for(int i=1;i<=n;i++) a[i]=rand()%2;
      for(int i=1;i<=m;i++){
        if(a[y[i]]==0&&a[x[i]]){
          now++;
        }
      }
      if(now>=sum) break;
    }
    cout<<now<<endl;
    for(int i=1;i<=m;i++) 
      if(a[y[i]]==0&&a[x[i]])
        cout<<i<<" ";
    puts("");
  }
  return 0;
}


目录
相关文章
|
1月前
|
机器学习/深度学习 安全 算法
【现代密码学】笔记3.1-3.3 --规约证明、伪随机性《introduction to modern cryphtography》
【现代密码学】笔记3.1-3.3 --规约证明、伪随机性《introduction to modern cryphtography》
65 0
|
1月前
|
存储 缓存 安全
|
10月前
|
机器学习/深度学习 算法
少样本学习系列(三)【Optimization-Based Methods】
少样本学习系列(三)【Optimization-Based Methods】
|
机器学习/深度学习 Ubuntu PyTorch
RoNIN: Robust Neural Inertial Navigation预训练模型测试
RoNIN: Robust Neural Inertial Navigation预训练模型测试
125 0
RoNIN: Robust Neural Inertial Navigation预训练模型测试
|
算法 数据挖掘 计算机视觉
YOLOv5的Tricks | 【Trick5】遗传算法实现超参数进化(Hyperparameter Evolution)
YOLOv5的Tricks | 【Trick5】遗传算法实现超参数进化(Hyperparameter Evolution)
696 0
YOLOv5的Tricks | 【Trick5】遗传算法实现超参数进化(Hyperparameter Evolution)
|
机器学习/深度学习 算法 算法框架/工具
传输丰富的特征层次结构以实现稳健的视觉跟踪 Transferring Rich Feature Hierarchies for Robust Visual Tracking
传输丰富的特征层次结构以实现稳健的视觉跟踪 Transferring Rich Feature Hierarchies for Robust Visual Tracking
114 2
传输丰富的特征层次结构以实现稳健的视觉跟踪 Transferring Rich Feature Hierarchies for Robust Visual Tracking
|
编译器 C++
C++ Trick:什么时候需要前置声明?
经常有C++开发的小伙伴提问: C++中要使用类A时,什么时候#include "a.h",什么时候用class A前置声明呢?
208 0
|
缓存 算法 调度
重新审视wake_wide启发式搜索算法
作者:张金利 马涛 云巅论剑
463 0
|
算法 数据库
线性一致性与全序广播------《Designing Data-Intensive Applications》读书笔记12
上一篇聊了聊构建分布式系统所面临的困难,这篇将着重讨论构建容错分布式系统的算法与协议。构建容错系统的最佳方法是使用通用抽象,允许应用程序忽略分布式系统中的一些问题。
1446 0

热门文章

最新文章