Clarke and chemistry

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 173    Accepted Submission(s): 95
Problem Description
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a junior student and took a chemistry exam.


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.
 
Input
The first line contains an integer
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)
 
Output
For each test case, if we can balance the equation, print
a
and b.
If there are multiple answers, print the smallest one,
a
is smallest then b
is smallest. Otherwise print NO.
 
Sample Input
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
 
Sample Output
2 3
NO Hint:
The first test case, $a=2, b=3$ can make equation right.
The second test case, no any answer.
 
Source
 
#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(枚举)的更多相关文章

  1. hdu 5625 Clarke and chemistry

    Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned i ...

  2. BestCoder Round #72

    由于第一次打,只能在div2打.(这么好的机会还没AK真是丢人) T1 Clarke and chemistry 枚举题不解释(我不会告诉你我上来WA了四发的) T2 Clarke and point ...

  3. hdu 5625

    Clarke and chemistry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  4. BestCoder Round #72 (div.2)

    后面的题目补不懂了 暴力 1001 Clarke and chemistry 这题也把我搞死了..枚举系数判断就行了 #include <cstdio> #include <algo ...

  5. 二进制枚举 + 容斥定理(hdoj 4336 )

    hdoj 4336 http://acm.hdu.edu.cn/showproblem.php?pid=4336 这是一道关于概率与期望的问题,其中   期望 =  1 / 概率 容斥原理  P =  ...

  6. 枚举+贪心 HDOJ 4932 Miaomiao's Geometry

    题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...

  7. HDOJ/HDU 1015 Safecracker(枚举、暴力)

    Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...

  8. HDOJ(HDU) 1562 Guess the number(水题,枚举就行)

    Problem Description Happy new year to everybody! Now, I want you to guess a minimum number x betwwn ...

  9. hdoj 4445 Crazy Tank 物理题/枚举角度1

    Crazy TankTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. 00-SQLite的SQL语法

    SQLite的SQL语法 SQLite库可以解析大部分标准SQL语言.但它也省去了一些特性并且加入了一些自己的新特性.这篇文档就是试图描述那些SQLite支持/不支持的SQL语法的.查看关键字列表. ...

  2. CSS——继承性

    继承性发生的前提是包含(嵌套关系). 1.文字颜色可以继承 2.文字大小可以继承 3.字体可以继续 4.字体粗细可以继承 5.文字风格可以继承 6.行高可以继承 总结:文字的所有属性都可以继承. 特殊 ...

  3. Python开发工具搭建-Pycharm

    PyCharm2017. 3.X专业版 安装使用. 注册码激活 本文以 Windows系统 为例: 1.开发工具获取及下载 Anaconda(Python 的集成工具 ) 下载地址: https:// ...

  4. NSOperationQueue和GCD的区别,以及在什么场合下使用

    1> GCD是纯C语言的API .NSOperationQueue是基于GCD的OC的封装. 2> GCD只支持FIFO队列,NSOperationQueue可以方便设置执行顺序,设置最大 ...

  5. CAD绘制一个线型标注(com接口VB语言)

    主要用到函数说明: _DMxDrawX::DrawDimRotated 绘制一个线型标注.详细说明如下: 参数 说明 DOUBLE dExtLine1PointX 输入第一条界线的起始点X值 DOUB ...

  6. PHP常用的设计模式

    工厂模式 工厂模式是我们最常用的实例化对象模式,是用工厂方法代替new操作的一种模式. 使用工厂模式的好处是如果你想要更改所实例化的类名等,则只需要更改该工厂方法内容即可,不需逐一寻找代码中具体实例化 ...

  7. hdu 4018 Parsing URL(字符串截取)

    题目 以下引用自百度百科: sscanf 的相关用法 头文件:#include<stdio.h>     1. 常见用法. 1 2 3 charbuf[512]; sscanf(" ...

  8. String s="a"+"b"+"c"+"d";创建了几个对象?

    对于如下代码: package reviewTest; /** * @ClassName: StringTest * @Description: 测试String的字符串相加优化 * @author ...

  9. MySQL中是索引

    MySQL中是索引: --.唯一索引: 一行中的内容不能一样, create t2( id int , num int, unique weiyisuiyin (id,num) ) --唯一; --约 ...

  10. Linux之iptables(二、基本认识和组成)

    iptables的基本认识 Netfilter组件 内核空间,集成在linux内核中 扩展各种网络服务的结构化底层框架 内核中选取五个位置放了五个hook(勾子) function(INPUT.OUT ...