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. 我的Android进阶之旅------>Android拍照小例子

    今天简单的学习了一下android拍照的简单实现. 当然该程序是个小例子,非常简单,没有什么复杂的操作,但是可以学习到Android 拍照API流程. 1.在布局文件中添加一个 surfaceView ...

  2. js 写table 函数

    //创建 table函数 function table(row,col,b,w) { document.write('<table border='+b+'>'); for(var i=0 ...

  3. 如何在cmd窗口启动Tomcat

    平时,一般使用tomcat/bin/startup.bat目录在windows环境启动Tomcat,或者使用IDE配置后启动. 下面来简单介绍下如果在cmd窗口直接输入命令启动Tomcat: 1.将t ...

  4. nodejs之简介及安装(一)

    @[nodejs|个人学习笔记] nodejs简介 什么是node.js Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境. 参考网站 一.nodejs.cn 二 ...

  5. HTML 表格入门

    每个表格都是由 table 标签开始. 每个表格行由 tr 标签开始. 每个表格数据由 td 标签开始. 这样是一行三列: <table border="1"> < ...

  6. Windows - 远程桌面无证书

    可以从命令行启动远程桌面,输入:mstsc /v:地址:端口 /admin

  7. Log4net 列

    配置 <configuration> <configSections> <section name="log4net" type="Syst ...

  8. Apache 2.4.7在CentOS6.4中安装配置反向代理解决单外网IP对应多个内网主机的方法实践

    欢迎转载,转载时请保留全文及出处. Apache 2.4.7在CentOS6.4中安装配置反向代理解决单外网IP对应多个内网主机的方法实践 Apache安装 下载源程序(http://httpd.ap ...

  9. C++程序设计实践指导1.10二维数组元素换位改写要求实现

    改写要求1:改写为以单链表和双向链表存储二维数组 改写要求2:添加函数SingleLinkProcess()实现互换单链表中最大结点和头结点位置,最小结点和尾结点位置 改写要求3:添加函数Double ...

  10. python调webservice和COM接口

    调webservice # -*- coding: cp936 -*- from suds.client import Client url = 'http://192.168.50.165/port ...