Clarke and chemistry

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 63    Accepted Submission(s): 33

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 AA

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

. Please calculate the stoichiometric coefficient a

of A

and b

of B

that aA + bB = C,\ \ a, b \in \text{N}^*

.

 
Input
The first line contains an integer T(1 \le T \le 10)

, the number of test cases.
For each test case, the first line contains three integers A, B, C(1 \le A, B, C \le 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

capital letters, guarantee X

of one valence only appear one time, 1 \le c \le 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
 
 
 http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=671&pid=1001 中文题意
枚举 a,b      代码长时间不写 手糙了
今天02网上找模板水过 明天补看
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#define LL __int64
using namespace std;
int t;
int a,b,c;
char ceshi[30]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char aa[30],bb[30],cc[30];
int aaa[30],bbb[30],ccc[30];
map<char,int> mp1;
map<char,int> mp2;
map<char,int> mp3;
int main()
{
while(scanf("%d",&t)!=EOF)
{
for(int i=1;i<=t;i++)
{
mp1.clear();
mp2.clear();
mp3.clear();
scanf("%d%d%d",&a,&b,&c);
getchar();
for(int j=1;j<=a;j++)
{
scanf("%c %d",&aa[j],&aaa[j]);
mp1[aa[j]]=aaa[j];getchar();
}
for(int j=1;j<=b;j++)
{
scanf("%c %d",&bb[j],&bbb[j]);
mp2[bb[j]]=bbb[j];getchar();
}
for(int j=1;j<=c;j++)
{
scanf("%c %d",&cc[j],&ccc[j]);
mp3[cc[j]]=ccc[j];getchar();
}
int k=0,g=0,ans;
int flag=0;
int ggg1,ggg2;
for(k=1;k<=99;k++)
{
for(g=1;g<=99;g++)
{
ans=0;
for(int kk=0;kk<=25;kk++)
{
if(mp1[ceshi[kk]]*k+mp2[ceshi[kk]]*g==mp3[ceshi[kk]]&&mp3[ceshi[kk]]!=0)
ans++;
}
if(ans==c)
{
ggg1=k;
ggg2=g;
flag=1;
break;
}
}
if(flag)
break;
}
if(flag)
printf("%d %d\n",ggg1,ggg2);
else
printf("NO\n"); }
}
return 0;
}

  

hdu 5625的更多相关文章

  1. hdu 5625 Clarke and chemistry

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

  2. HDU 2078 复习时间

    http://acm.hdu.edu.cn/showproblem.php?pid=2078 Problem Description 为了能过个好年,xhd开始复习了,于是每天晚上背着书往教室跑.xh ...

  3. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  5. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  6. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  8. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  9. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

随机推荐

  1. 小程序页面的四种文件(JSON、WXML、WXSS、JS)加载顺序

    一个小程序页面由四种文件组成: 1)json 页面配置文件 2)js 页面逻辑文件(必需) 3)wxml 页面结构文件(必需) 4)wxss 页面样式文件 这四个文件的加载顺序: 第一步: 加载页面j ...

  2. logisitic回归

    线性回归目的是找到一条直线(或者超平面)尽可能地接近所有的训练数据点,而对数几率回归的目的是找到一条直线(或者超平面)尽可能地分开两种不同类别的数据点. 对数几率回归感觉更像是一个分类问题.https ...

  3. C++基础和STL,Effective C++笔记

    这个作者总结的c++基础,特别好. 可以看看. http://blog.csdn.net/tham_/article/details/51169792

  4. JavaScript初探系列之数组的基本操作

    在程序语言中数组的重要性不言而喻,JavaScript中数组也是最常使用的对象之一,数组是值的有序集合,由于弱类型的原因,JavaScript中数组十分灵活.强大,不像是Java等强类型高级语言数组只 ...

  5. android项目中导入actionbarsherlock 需要注意的地方

    1,在导入actionbarsherlock 这个library时,如果一直报" Invalid Project Description" ;  解决办法:  android中li ...

  6. LintCode-5.第k大元素

    第k大元素 在数组中找到第k大的元素 注意事项 你可以交换数组中的元素的位置 样例 给出数组 [9,3,2,4,8],第三大的元素是 4 给出数组 [1,2,3,4,5],第一大的元素是 5,第二大的 ...

  7. OSPF学习中的问题

    OSPF对接两方,对设置的要求,哪些参数必须相同 (HELLO &dead interval, area ID, authentation, 末节区域(option中的E位), network ...

  8. idea dubbo jar error:cvc-complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 'dubbo:application' 的声明

    声明: 出现这个错误的情形是,在idea开发环境里面运行是没有问题的,使用哦idea自带的打包工具生成jar之后,运行jar的时候报的这个错误,如果不是这个情况,这篇文章可能不适用. 主要的原因是sp ...

  9. android gradle打包常见问题及解决方案

    背景: 问题: Q1: UNEXPECTED TOP-LEVEL ERROR: java.lang.OutOfMemoryError: Java heap space at com.android.d ...

  10. 第五部分shell项目一监控脚本

    需求: 使用shell定制各种个性化告警工具,但需要统一化管理.规范化管理. 思路:指定一个脚本包,包含主程序.子程序.配置文件.邮件引擎.输出日志等.主程序:作为整个脚本的入口,是整个系统的命脉.配 ...