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
 
 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
using namespace std;
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1000000
#define inf 1e12
int a,b,c;
int mp[][];
int mpp[][];
int vis[];
int main()
{
int t;
scanf("%d",&t);
while(t--){
memset(mpp,,sizeof(mpp)); scanf("%d%d%d",&a,&b,&c);
char s[];
int cnt;
for(int i=;i<a;i++){
scanf("%s%d",s,&cnt);
int index = s[]-'A';
mpp[][index]+=cnt;
//printf("1---%d\n",mp[0][index]);
}
for(int i=a;i<a+b;i++){
scanf("%s%d",s,&cnt);
int index = s[]-'A';
mpp[][index]+=cnt;
//printf("2---%d\n",mp[1][index]);
}
for(int i=a+b;i<a+b+c;i++){
scanf("%s%d",s,&cnt);
int index = s[]-'A';
mpp[][index]+=cnt;
//printf("3---%d\n",mp[2][index]);
} int i,j;
int flag=;
for(i=;i<=;i++){
for(j=;j<=;j++){
for(int k=;k<;k++){
mp[][k]=mpp[][k];
mp[][k]=mpp[][k];
mp[][k]=mpp[][k];
}
memset(vis,,sizeof(vis));
for(int k=;k<;k++){
mp[][k]*=i;
mp[][k]*=j;
}
int w=;
for(int k=;k<;k++){
if(mp[][k]){
if(mp[][k]+mp[][k] == mp[][k]){
vis[k]=;
}else{
w=;
break;
}
}
} if(w==){
for(int k=;k<;k++){
if(vis[k]== && (mp[][k] || mp[][k] || mp[][k])){
w=;
break;
}
}
}
if(w==){
flag=;
break;
}
}
if(flag==) break;
}
if(flag==){
printf("%d %d\n",i,j);
}else{
printf("NO\n");
}
}
return ;
} //A 6 2 12
//B 6 3 18
//C 12 5 60

hdu 5625 Clarke and chemistry的更多相关文章

  1. hdu 5625

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

  2. HDU 5628 Clarke and math——卷积,dp,组合

    HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...

  3. hdu 5565 Clarke and baton 二分

    Clarke and baton Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  4. hdu 5563 Clarke and five-pointed star 水题

    Clarke and five-pointed star Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/show ...

  5. hdu 5465 Clarke and puzzle 二维线段树

    Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  6. hdu 5464 Clarke and problem dp

    Clarke and problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...

  7. HDU 5628 Clarke and math dp+数学

    Clarke and math 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5628 Description Clarke is a patient ...

  8. hdu 5463 Clarke and minecraft

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5463 Clarke and minecraft Time Limit: 2000/1000 MS (J ...

  9. HDU 5464 Clarke and problem 动态规划

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5464 Clarke and problem  Accepts: 130  Submissions: ...

随机推荐

  1. UDP通讯协议

    常见的通讯协议有udp和tcp. 先来简单了解一下这两个协议各自的特点: UDP: --将数据及源.目的封装在数据包中,不需要建立连接: --每个数据包的大小限制在64k以内: --因无连接,是不可靠 ...

  2. PHP设计模式笔记一:准备工作 -- Rango韩老师 http://www.imooc.com/learn/236

    一.编程字体选择 1.选择等宽字体 包括Courier New ,Consolas,Source Code Pro(推荐) 2.环境搭建(建议easyPHP) 二.开发符合PSR规范的基础框架 PSR ...

  3. RESTEasy 3.X Helloworld

    最近呢,RESTEasy也升级了.升到了3.X. 官网:http://www.jboss.org/resteasy 集成使用也非常简单(相比SOAP而言) 第一步:下载jar包 resteasy是托管 ...

  4. SQL参数化

    本文来自:caodonglin 一.SQL参数化为什么能防注入? 因为执行计划被重用了,所以可以防SQL注入. 下面有两段SQL     正常SQL: 1 select COUNT(1) from C ...

  5. jqGrid源代码分析(一)

    废话少说.先上grid.base.js 整体结构图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3B5MTk4ODEyMDE=/font/5a6L5L2 ...

  6. 【剑指offer】替换字符串中的空格

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/25002199 剑指offer上的第四道题目,在九度OJ上測试通过,但还是有些问题.由于是用 ...

  7. Android应用程序资源的查找过程分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8806798 我们知道,在Android系统中, ...

  8. Oracle安装基本步骤

    安装数据库 .建立用户组及用户 groupadd oinstall groupadd dba groupadd oper useradd -g oinstall -G dba oracle passw ...

  9. [汇编学习笔记][第十三章int指令]

    第十三章int指令 13.1 int指令 格式: int n, n 为中断类型码 可以用int指令调用任何一个中断的中断处理程序(简称中断例程). 13.4 BIOS和DOS 所提供的中断例程 BIO ...

  10. python-生成随机字符

    需求: 随机生成6位的大写字母: 方法一: #!/usr/bin/env python # -*- coding:utf-8 -*- import random li = [] for i in ra ...