hdoj--5625--Clarke and chemistry(枚举)
Clarke and chemistry
But he did not get full score in this exam. He checked his test paper and found a naive mistake, he was wrong with a simple chemical equation balancer.
He was unhappy and wanted to make a program to solve problems like this.
This chemical equation balancer follow the rules:
Two valences A
combined by |A|
elements and B
combined by |B|
elements.
We get a new valence C
by a combination reaction and the stoichiometric coefficient of
C
is 1
Please calculate the stoichiometric coefficient a
of A
and b
of B
that aA+bB=C, a,b∈N
T(1≤T≤10)
the number of test cases.
For each test case, the first line contains three integers
A,B,C(1≤A,B,C≤26)
denotes |A|,|B|,|C|
respectively.
Then A+B+C
lines follow, each line looks like X c
denotes the number of element X
of A,B,C
respectively is c
(X
is one of 26
capital letters, guarantee X
of one valence only appear one time, 1≤c≤100
a
and b
If there are multiple answers, print the smallest one,
a
is smallest then b
is smallest. Otherwise print NO.
2
2 3 5
A 2
B 2
C 3
D 3
E 3
A 4
B 4
C 9
D 9
E 9
2 2 2
A 4
B 4
A 3
B 3
A 9
B 9
2 3
NO Hint:
The first test case, $a=2, b=3$ can make equation right.
The second test case, no any answer.
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int A[27],B[27],C[27];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
char op[2];
bool flag=true;
int d,maxx=0;
memset(B,0,sizeof(B));
memset(C,0,sizeof(C));
memset(A,0,sizeof(A));
for(int i=0;i<a;i++)
{
scanf("%s%d",op,&d);
A[op[0]-'A']=d;
}
for(int i=0;i<b;i++)
{
scanf("%s%d",op,&d);
B[op[0]-'A']=d;
}
for(int i=0;i<c;i++)
{
scanf("%s%d",op,&d);
C[op[0]-'A']=d;
// maxx=max(maxx,d/A[op[0]-'A']);
// maxx=max(maxx,d/B[op[0]-'A']);
}
int i,j,k;
int min,x,y;
for(i=1;i<=1000&&flag;i++)
for(j=1;j<=1000;j++)
{
int s;
for(s=0;s<26;s++)
{
x=i*A[s]+j*B[s];
y=C[s];
if(x==y)
continue;
else break;
}
if(s==26) flag=false;
if(!flag) break;
}
if(!flag) printf("%d %d\n",i-1,j);
else printf("NO\n");
}
return 0;
}
hdoj--5625--Clarke and chemistry(枚举)的更多相关文章
- hdu 5625 Clarke and chemistry
Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned i ...
- BestCoder Round #72
由于第一次打,只能在div2打.(这么好的机会还没AK真是丢人) T1 Clarke and chemistry 枚举题不解释(我不会告诉你我上来WA了四发的) T2 Clarke and point ...
- hdu 5625
Clarke and chemistry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- BestCoder Round #72 (div.2)
后面的题目补不懂了 暴力 1001 Clarke and chemistry 这题也把我搞死了..枚举系数判断就行了 #include <cstdio> #include <algo ...
- 二进制枚举 + 容斥定理(hdoj 4336 )
hdoj 4336 http://acm.hdu.edu.cn/showproblem.php?pid=4336 这是一道关于概率与期望的问题,其中 期望 = 1 / 概率 容斥原理 P = ...
- 枚举+贪心 HDOJ 4932 Miaomiao's Geometry
题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...
- HDOJ/HDU 1015 Safecracker(枚举、暴力)
Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...
- HDOJ(HDU) 1562 Guess the number(水题,枚举就行)
Problem Description Happy new year to everybody! Now, I want you to guess a minimum number x betwwn ...
- hdoj 4445 Crazy Tank 物理题/枚举角度1
Crazy TankTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- jQuery——节点操作
创建节点 1.$():创建一个li标签 $("<li class='aaa'>我是li标签</li>") 2.html():创建一个li标签并同时添加到ul ...
- CSS——text-indent
在h1标签里套入a标签并写上文字,有利于seo,但是文字如何隐藏呢?一般都是a标签变成内联块并首行缩进为负值. <!DOCTYPE html> <html lang="en ...
- [Windows Server 2012] PHPWind安全设置
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★[护卫神·V课堂]是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:PHPWin ...
- Find the build UUID in a Crash Report
1) Find the build UUID in a Crash Report The first line in the "Binary Images:" section of ...
- 5.21leetcode练习
目录 两数之和 题目 答案 整数反转 题目 思路及答案 回文数 题目 思路及答案 希望每天进步一点点 两数之和 题目 新手司机上路,光荣翻车,没想出来.借了别人的答案,自行领会 答案 整数反转 题目 ...
- PHP 之用证书对数据进行签名、验签、加密、解密
/** * 对数据进行签名 * $data = 'If you are still new to things, we’ve provided a few walkthroughs to get yo ...
- 6 个 Linux 运维典型问题,大牛的分析解决思路在这里
作为一名合格的 Linux 运维工程师,一定要有一套清晰.明确的解决故障思路,当问题出现时,才能迅速定位.解决问题,这里给出一个处理问题的一般思路: 重视报错提示信息:每个错误的出现,都是给出错误提示 ...
- Python os模块和time模块 day4
一.os模块 print(os.listdir(r'/Users/smh/Desktop/整理'))#os.listdir() 列出某个目录下面的文件夹/文件 print(os.path.isfile ...
- 57 和为S的数字
题目一:和为S的两个数字 输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 输出描述: 对应每个测试案例,输出两个数,小 ...
- Vector 和 Array 区别
1:array 定义的时候必须定义数组的元素个数;而vector 不需要:且只能包含整型字面值常量,枚举常量或者用常量表达式初始化的整型const对象, 非const变量以及需要到运行阶段才知道其值的 ...