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月前
|
存储 缓存 安全
|
1月前
|
机器学习/深度学习 安全 算法
【现代密码学】笔记3.1-3.3 --规约证明、伪随机性《introduction to modern cryphtography》
【现代密码学】笔记3.1-3.3 --规约证明、伪随机性《introduction to modern cryphtography》
70 0
|
1月前
|
安全 算法 API
【现代密码学】笔记4--消息认证码与抗碰撞哈希函数《introduction to modern cryphtography》
【现代密码学】笔记4--消息认证码与抗碰撞哈希函数《introduction to modern cryphtography》
69 0
|
机器学习/深度学习 算法 数据挖掘
Machine Learning-L15-EM算法全解析(上)
Machine Learning-L15-EM算法全解析
Machine Learning-L15-EM算法全解析(上)
|
算法 数据挖掘 Python
Machine Learning-L15-EM算法全解析(下)
Machine Learning-L15-EM算法全解析(下)
Machine Learning-L15-EM算法全解析(下)
|
算法 数据挖掘 计算机视觉
YOLOv5的Tricks | 【Trick5】遗传算法实现超参数进化(Hyperparameter Evolution)
YOLOv5的Tricks | 【Trick5】遗传算法实现超参数进化(Hyperparameter Evolution)
701 0
YOLOv5的Tricks | 【Trick5】遗传算法实现超参数进化(Hyperparameter Evolution)
|
机器学习/深度学习 算法 算法框架/工具
传输丰富的特征层次结构以实现稳健的视觉跟踪 Transferring Rich Feature Hierarchies for Robust Visual Tracking
传输丰富的特征层次结构以实现稳健的视觉跟踪 Transferring Rich Feature Hierarchies for Robust Visual Tracking
116 2
传输丰富的特征层次结构以实现稳健的视觉跟踪 Transferring Rich Feature Hierarchies for Robust Visual Tracking
|
编解码
猪笼草表面连续定向输水Continuous directional water transport on the peristome surface of Nepenthes alata-2016-阅读笔记
打破了传统水往下流的思路,仿生猪笼草表面结构,提出定向水传输结构。
|
数据可视化 算法
Paper:《Greedy Function Approximation: A Gradient Boosting Machine贪心函数逼近:梯度提升机器模型》翻译与解读—PDP来源
Paper:《Greedy Function Approximation: A Gradient Boosting Machine贪心函数逼近:梯度提升机器模型》翻译与解读—PDP来源