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. Java开发工程师(Web方向) - 04.Spring框架 - 第2章.IoC容器

    第2章.IoC容器 IoC容器概述 abstract: 介绍IoC和bean的用处和使用 IoC容器处于整个Spring框架中比较核心的位置:Core Container: Beans, Core, ...

  2. python基本数据类型——集合

    集合 无序可变序列,集合中元素不允许重复,即每个元素都是唯一的 集合中的元素按照升序排列 # 创建集合 >>aset = set([0,2,4,5,7,2,3,5,9,0]) >&g ...

  3. visionpro9.0破解

    visionpro9.0软件下载 提供一个visionpro9.0视频教程学习网站:点击下面链接进入. ------------------------Halcon,Visionpro高清视频教程,点 ...

  4. 小程序的picker的range 是一个 Object Array (对象数组)

    小程序的picker的range 是一个 Object Array (对象数组) 数据: array: [{'id':1,'name':'Android'},{'id':2,'name':'IOS'} ...

  5. logstash+elasticsearch 错误摘记

    [2017-09-17T06:00:22,511][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception ...

  6. Centos下的SVN搭建

    需求: 搭建SVN实现本地开发环境,方便线上代码的更新. 步骤: 1. 安装SVN服务 yum install -y subversion 2.创建SVN代码库的目录.创建版本库 mkdir -p / ...

  7. dataTables工作总结

    近期在工作中用到了dataTables,现在总结一下在工作中遇到的问题以及解决方法,如有不妥之处希望多多指教,定会改进. 首先这里用的是coloradmin框架,在vs环境下开发. 这里写一个容器用于 ...

  8. 《剑指offer》---字符串的全排列

    本文算法使用python3实现 1.问题一 1.1 题目描述:   输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc ...

  9. Sparsity Invariant CNNs

    文章链接 Abstract 本文研究稀疏输入下的卷积神经网络,并将其应用于稀疏的激光扫描数据的深度信息完成实验.首先,我们表明,即使当丢失数据的位置提供给网络时,传统卷积网络在应用于稀疏数据时性能也很 ...

  10. Launch Image消失时添加动画

    CGSize viewSize = self.window.bounds.size; NSString *viewOrientation = @"Portrait"; //横屏请设 ...