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 ...
随机推荐
- Less——less基本安装
1.下载node.js 我们需要NodeJ运行LESS示例. 要下载NodeJ,请打开链接https://nodejs.org/en/ 2.node.js安装是否正确 在cmd中输入lessc -v, ...
- Oracle基础理论笔记(一):模式概念
---oracle 10g 1.在oracle数据库中,数据对象是以模式为单位进行组织和管理的.模式是指一系列的逻辑数据结构或对象的集合. 2.模式与用户名相对应,一个模式只能对应一个用户,并且该模式 ...
- 【译】x86程序员手册19-6.3.2数据访问的约束
6.3.2 Restricting Access to Data 数据访问的约束 To address operands in memory, an 80386 program must load ...
- 微信开发配置JSSDK,注入权限验证,以及invalid signature签名错误解决
在微信开发中很多功能都要用到微信JSSDK,关于JSSDK的使用,微信官方的文档已经比较详细,一定要仔细去看文档. <script src="https://res.wx.qq.com ...
- Centos7搭建nginx并提供外网访问
搭建nginx之后,80端口,其他机器无法访问 查询端口是否开启 firewall-cmd --query-port=80/tcp 永久开放80端口 firewall-cmd --permanent ...
- C#鸡翁百鸡
一个for static void Main(string[] args) { int x, y, z; ; x <= ; x++) { - * x) % == ) { y = ( - * x) ...
- CF1148D-Dirty Deeds Done Dirt Cheap
这轮CF怎么充满了替身啊233(这是场只有替身使者才能看见的比赛) 题解可以看官方的 这里就是记录下自己当初是怎么没做上的233 忽视掉了分类后pair本身就会带有的性质(a<b or a> ...
- solaris roles cannot login directly
oracle@solaris:~$ su - root Password: Oracle Corporation SunOS root@solaris:~# cat /etc/user_attr # ...
- 【第8篇】:Python之面向对象
python之--------封装 一.封装: 补充封装: 封装: 体现在两点: 1.数据的封装(将数据封装到对象中) obj = Foo('宝宝',22) 2.封装方法和属性,将一类操作封装到一个类 ...
- 标准C 语言总结
***************C语言****************** --day01-- Linux是一个和Windows类似的操作系统 通常通过终端软件使用Linux操作系统 终端软件里只能使用 ...