UVa340 Master-Mind Hints
来源:互联网 发布:淘宝售后退款期限 编辑:程序博客网 时间:2024/04/23 21:33
这个题目巨长。略过,A同列相同元素统计即可。A是数字在两个序列中出现过位置相同
主要是B,数字在两个序列中都出现过的次数 = 数字在两个序列中都出现过但位置不对 + 数字在两个序列中都出现过位置相同
B = 数字在两个序列中都出现过的次数 - A;
数字在两个序列中出现的次数应该是取次数较少的,例如在答案序列中出现过2次,测试序列中出现过3次,实际上在两个序列中都出现过两次,而不是都出现过三次,所以每次取最小
#include<stdio.h>int main(void){ int a[1000], b[1000], n; int kase = 0; while(scanf("%d", &n) == 1 && n) { for(int i = 0; i < n; i++) scanf("%d", &a[i]); printf("Game %d:\n", ++kase); while(1) { int A = 0, B = 0; for(int i = 0; i < n; i ++) { scanf("%d", &b[i]); if (a[i] == b[i]) A++; } if (b[0] == 0) break; for(int d = 1; d <= 9; d++) { int c1 = 0, c2 = 0; for(int i = 0; i < n; i++)//统计两个序列中出现的次数 { if (a[i] == d) c1++; if (b[i] == d) c2++; } if (c1 < c2) B+= c1; else B+=c2;//两个序列中都出现的次数min(c1, c2) } printf(" (%d,%d)\n", A, B-A); } }}
阅读全文
0 0
- uva340 - Master-Mind Hints
- UVa340 Master-Mind Hints
- UVA340 - Master-Mind Hints
- UVA340 Master-Mind Hints
- uva340 - Master-Mind Hints
- UVA340 - Master-Mind Hints
- UVa340 Master-Mind Hints
- uva340 Master-Mind Hints
- UVa340-Master-Mind Hints
- UVa340 Master-Mind Hints
- UVA340 UVALive5448 Master-Mind Hints
- Master-Mind Hints—UVa340
- Master-Mind Hints UVa340 排序&&查找
- UVa340——Master-Mind Hints
- 340 - Master-Mind Hints
- uva_340 - Master-Mind Hints
- uva_340 - Master-Mind Hints
- 340 - Master-Mind Hints
- 享元模式
- SHUOJ小偷偷东西
- [深度学习]Softmax 交叉熵
- Unity Update与LateUpdate执行顺序之坑
- 【15】前端开发--面试题整理(JS篇)
- UVa340 Master-Mind Hints
- Java中Exception和Error的区别
- 基本使用方法之一
- 西瓜书总结与回顾(一)------体系与方法
- 模拟concat方法进行数组拼接,模拟set函数,进行数组去重;
- oracle中数据库名、数据库实例名、SID的区别
- POJ 2823 Sliding Window 【单调队列】
- Maven does not create the "/target/m2e-wtp/web-resources" folder
- Android开发工具下载