CF-63C - Bulls and Cows(枚举)

【漆学军】MT4进阶到MT5速成之路(2)获取持仓 MT5在持仓获取上,要比MT4复杂些,分两部分,获取持仓和挂单采用了不同的方法。 一、获取持仓中的buy和sell单 int b=0;//获取buy单个数 int s=0;//获取sell单个数 double lot_total_buy=0;//获取持仓中buy单的总手数 double lot_total_sell=0;//获取持仓中sell单的总手数 for(int i=0; i<PositionsTotal(); i++) { ulong ticket=Positi 阅读详情

C - Bulls and Cows
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.

The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "x bulls y cows". xrepresents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.

For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one).

When the guesser is answered "4 bulls 0 cows", the game is over.

Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.

Input

The first input line contains an integer n (1 ≤ n ≤ 10) which represents the number of already made guesses. Then follow n lines in the form of "ai bi ci", where ai is the i-th experimental number, bi is the number of bulls, ci is the number of cows (1 ≤ i ≤ n, 0 ≤ bi, ci, bi + ci ≤ 4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.

Output

If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.

Sample Input

Input
2
1263 1 2
8103 2 1
Output
Need more data
Input
2
1234 2 2
1256 0 2
Output
2134
Input
2
0123 1 1
4567 1 2
Output
Incorrect data

思路:枚举0-9999,看符合条件的数有几个,没有说明信息有误,一个,答案唯一,多个,需要更多信息


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
class node
{
  public:int a,b,c;
}f[111];
int n;
int main()
{
  while(cin>>n)
  {
    for(int i=0;i<n;++i)
    {
      cin>>f[i].a>>f[i].b>>f[i].c;
    }
    int ans=0,kkans;
    int a,b,c,d,z,bb,cc,zz;
    for(int i=0;i<10000;++i)
    { z=i;a=z%10;z/=10;b=z%10;z/=10;c=z%10;z/=10;d=z%10;
      if(a==b||a==c||a==d||b==c||b==d||c==d)continue;
      bool yes=1;
      for(int j=0;j<n;++j)
      { bb=0;cc=0;
        z=f[j].a;
        zz=z%10;
        if(a==zz)bb++;if(b==zz)cc++;if(c==zz)cc++;if(d==zz)cc++;
        z/=10;zz=z%10;
        if(b==zz)bb++;if(a==zz)cc++;if(c==zz)cc++;if(d==zz)cc++;
        z/=10;zz=z%10;
        if(c==zz)bb++;if(a==zz)cc++;if(b==zz)cc++;if(d==zz)cc++;
        z/=10;zz=z%10;
        if(d==zz)bb++;if(a==zz)cc++;if(b==zz)cc++;if(c==zz)cc++;
        if(bb!=f[j].b||cc!=f[j].c){yes=0;break;}
      }
      if(yes){ans++;kkans=i;}
    }
    if(ans==0)cout<<"Incorrect data\n";
    else if(ans==1)printf("%04d\n",kkans);
    else cout<<"Need more data\n";
  }
}



操作系统期末大题类型题解 额,OS主要这回考程序分析题,PV操作、生产者消费者啊,哲学家进餐问题,死锁问题啊,如何避免死锁,经典银行家算法,页面置换算法啥的,磁盘调度......总计还有很多,就不一一说了 PV操作 谈到PV操作,首先要了解什么是信号量,其实就是用来解决互斥与同步问题的,分为原语wait(S)和signal(S),也就是我们常说的PV操作,在这里给出王道上的概念 wait(S){ while(S>0) S=S-1; } signal(S){ S=S+1; } 记录型信号量 阅读详情

相关推荐

STC8G1K08A的10位PWM避坑指南:为什么你的占空比调节总失效?(附寄存器操作时序图)

本文深入剖析了STC8G1K08A单片机10位PWM功能中占空比调节失效的核心原因,揭示了数据手册未明确指出的寄存器操作时序陷阱。通过对比错误与正确配置的波形,文章指出关键在于更新占空比高2位前需临时关闭PWM输出,并提供了经过验证的安全操作宏与函数库,帮助开发者彻底解决此问题,实现0%-100%的平滑控制。

yyy34的博客 747

CF63C Bulls and Cows 超详细题解

链接: 原题链接 题目描述 The “Bulls and Cows” game needs two people to play. The thinker thinks of a number and the guesser tries to guess it. The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number m

Syc1102g的博客 802

基于python的电商评论文本分析

本文基于京东平台安井手抓饼2000余条评论数据,运用Python文本分析技术(包括分词、词频统计、LDA主题模型等)探究消费者评价特征。研究发现:1)产品评价聚焦口味("好吃")、性价比("一分钱")和便捷性("早餐");2)京东物流服务获得高度认可;3)销售旺季集中在11月至次年1月。分析揭示了速冻食品消费者的核心关注点,为商家优化产品与服务提供数据支持,同时展示了文本挖掘技术在电商评论分析中的实用价值。

weixin_50902344的博客 8347

Bulls and Cows:比较两数组位置与元素完全相同、仅元素相同的的情况

You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t

小雄鹿的博客 342

RTKLIB使用方法(喂饭版)(三)——RTKPOST

应用OTL校正需要在“files”的“ocean loading BLQ format”中配置OTL文件。应用极潮需要在“files”的“EOP data file”配置ERP(地球旋转参数)文件。RAIM FDE:设置是否启用RAIM(接收机自主完整性监控)FDE(故障检测和排除)功能。点击下方的“save”可以把配置保存成文件,点击“load”就可以把配置文件加载出来。4接收机动态模型/地球潮汐矫正:设置流动站接收机动力学模型,只可以使用在DGPS/DGNSS或动态模型中。选择流动站天线的类型。

A2020713的博客 1万+

iPhone用户必看:不装App也能搞定GitHub 2FA验证的3种方法(附恢复码管理技巧)

本文为iPhone用户提供了无需安装第三方App即可完成GitHub双重身份验证(2FA)的三种原生方案:利用相机扫码与iCloud钥匙串自动填充、使用iCloud钥匙串内置的TOTP验证码生成器,以及借助Safari浏览器扩展。文章详细解析了每种方法的操作步骤、适用场景,并重点强调了恢复码的安全管理与多层备份策略,帮助开发者在提升账户安全的同时,享受苹果生态的无缝便捷体验。

weixin_29324401的博客 654

c# leetcode 299. 猜数字游戏(哈希)

这道题目终于读懂了,曾经很多人都不懂,或许因为没有真正仔细的审题,重点标红仔细读 你正在和你的朋友玩猜数字(Bulls and Cows)游戏:你写下一个数字让你的朋友猜。每次他猜测后,你给他一个提示,告诉他有多少位数字和确切位置都猜对了(称为“Bulls”, 公牛),有多少位数字猜对了但是位置不对(称为“Cows”, 奶牛)。你的朋友将会根据提示继续猜,直到猜出秘密数字。 请写出一个根据秘...

us2019的博客 473

第14.10章 高翔博士最新开源框架Lightning-LM源码解读(十):在线定位run_loc_online涉及到的核心模块总结

本文对Lightning-LM激光SLAM定位框架进行了全面剖析。该框架是一个轻量高效的激光雷达建图与定位系统,支持3D SLAM、动态图层管理等功能。文章首先介绍了项目概况和源码结构,包括核心模块如定位系统(loc_system)、激光匹配(lidar_loc)和位姿图优化(pose_graph)等。接着详细解析了各模块的关键函数和运行流程,如数据接收处理、NDT匹配和位姿优化等。最后总结了学习该框架所需的C++知识要点,包括智能指针、多线程编程等现代C++特性。该分析为SLAM开发者提供了实用的架构参考

行知SLAM 801

CodeForces - 63C Bulls and Cows(暴力求解)

Bulls and Cows Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Description The "Bulls and Cows" game needs two people to play. The thinker thi

小G的ACM之路 1345

Python画柱状图(双柱状图,三柱状图)且显示对应数值

使用python实现双柱状图和三柱状图,并且在柱状图形的顶部显示对应数值;

yue200403的博客 1万+

构建自己的 Qt 插件系统

Qt 本身提供了插件相关的技术,但并没有提供一个通用的插件框架!倘若要开发一个较大的 GUI 应用程序,并希望使其可扩展,那么拥有这样一个插件框架无疑会带来很大的好处。

青春不老,奋斗不止! 2万+

.NET 内存泄漏根因剖析:GC 自动回收背后的生命周期陷阱

在 .NET 开发中,GC(垃圾回收)被视为自动内存管理的核心机制,但许多开发者误以为对象不再使用时会被立即回收。实际上,GC 通过可达性扫描判断对象存活,只要从根集合(如静态字段、事件订阅、Timer 回调、闭包捕获)仍可访问,对象便不会被回收,从而导致内存泄漏。理解对象生命周期与根引用的关系,是排查 .NET 内存问题的关键。通过 dotnet-dump、dotnet-gcdump 等工具,可以精准定位持对象存活的确切引用链,从根源上修复泄漏。本文结合真实案例,梳理了常见根引用场景与设计期避坑清单,帮助

weixin_34130389的博客 449

基于Qt C++开发一个体测数据管理系统

advice.dietAdvice = "饮食建议:\n1. 控制总热量摄入,每天减少300-500大卡\n2. 减少精制碳水(白米饭、白面包、甜食)\n3. 增加优质蛋白和膳食纤维摄入\n4. 烹饪方式以蒸、煮、烤、凉拌为主,减少油炸\n5. 晚餐适量减少,睡前3小时避免进食";dataTable->setHorizontalHeaderLabels({"ID", "用户名", "身高(cm)", "体重(kg)", "BMI", "体脂率(%)", "记录时间"});

寒寒豆豆软件公司的博客 192

LeetCode Bulls and Cows

1232131 转载于:https://www.cnblogs.com/ZHONGZHENHUA/p/10924532.html

weixin_30325487的博客 131

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

CF 593 A 2Char(选择合适的枚举方式)

题目链接: CF 593 A 2Char 题意: 给出n个只含小写英文字母的字符串,选择若干字符串,拼成一个最多只含两种字母的最长的字符串,输出最长字符串长度。 分析: 我是选择枚举每个最多只含两种字母字符串,然后遍历其他只含改字符串所拥有字母的字符串,最后在处理下都是单种类字母字符串的拼接,这样写不仅代码冗长,而且也容易出错。 看了别人家的代码,发现可以枚举最终字符串含有的所有可能的字

ramay7 500

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Bulls and Cows

You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint tha...

IT成长之路 388

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

LeetCode -- Bulls and Cows

LeetCode -- Bulls and Cows

我的英文站点:https://iorilan.medium.com/ 2115

cf 978d 枚举

题意: n个数组成的序列a,每个数可以进行减1、不变、加1这3种操作的1种,是否可以把该序列变为等差数列。若可以,输出最小改变次数,若不可以,输出-1。1 &lt;= n &lt;= 1e6。 题解: 1.枚举首尾两个数字,共9种情况,计算出公差dis。然后判断第i个数字会不会变成a[1] + dis * (i - 1)。 #include&lt;bits/stdc++.h&gt; #d...

Irving0323的博客 408

[299] Bulls and Cows

统计两个字符串中位置相同且值相同的元素个数和位置不同但值相同的元素个数。

camlot的博客 1063

USACO-Section 1.2 Milking Cow[枚举]

枚举

smm的博客 509

leetcode 299. Bulls and Cows 猜数字游戏 + 直接统计 + 很棒的做法

You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint tha

JackZhangNJU的专栏 760

cf B. Pairs(思维:枚举)

题意:给你m组二元组(x,y),问你是否可以找到两个点,使得每个二元组里都含有这连个点之一。 思路:首先,我们先分析下题意。 让找两个点,使得每个二元组都含有这两个之一,那么任意一个二元组中都含有这两个点之一。 我们不妨枚举第一个二元组。 下面分类讨论, 1、这个二元组的两个点恰好是要找的那两个点。 2、这个二元组可能只含有一个要找的点 2、1 可能是第一个点 2、2可能是...

一身清贫怎敢入繁华 430

[LeetCode] Bulls and Cows 公母牛游戏

  You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret number and ask your friend to guess it, each time your friend guesses a number, you give a hint, the h...

weixin_33989780的博客 195

Bulls and Cows问题及解法

299. Bulls and Cows LeetCode

刘天的博客 4107

CF#368 B. Bakery (暴力枚举)

B. Bakery time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Masha wants to open her own bakery and bake muffi

blanKey的博客 524

猜数字游戏Bulls and Cows的解法

猜数字(又称 Bulls and Cows )是一种古老的的密码破译类益智类小游戏,起源于20世纪中期,一般由两个人或多人玩,也可以由一个人和电脑玩。查了网上很多关于这个游戏的帖子,大多都是计算机出题,人来猜。根据百度百科的介绍,有非常多种方法可以实现七步之内猜出答案。下面我就介绍其中最简单的一种也是我唯一会的一种方法。.........

weixin_44946764的博客 4660
上一篇: CF-63D - Dividing Island(水题)
下一篇: CF-63E - Sweets Game(记忆化搜索dp+状态压缩)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值