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. Linux CPU 亲和性

    在Linux中,我们知道可以通过nice.renice命令改变进程的执行优先级,优先级高的进程优先执行,从而一定程度上保证重要任务的运行. 除了nice.renice外,可以通过CPU affinit ...

  2. OS快速开发必备

    github:https://github.com/koknine (终于改成以前的了) 当前移动互联网行业太火爆,移动端的需求日益增长,很多开发人员每天都应对着各种需求,作为一名iOS开发人员,对于 ...

  3. spring容器IOC原理解析

    原理简单介绍: Spring容器的原理,其实就是通过解析xml文件,或取到用户配置的bean,然后通过反射将这些bean挨个放到集合中,然后对外提供一个getBean()方法,以便我们获得这些bean ...

  4. 怎样实现IOS开发中的数据存储方式

    iOS 开发中,一般有如下几种数据存储方式.需要根据具体的业务场景,选择 合适的数据存储方式. (1)  用户默认设置 – 这种情况通常不需要用户干预,如游戏通关信息,Video 播放记录,或者 Ap ...

  5. java遍历泛型的方法

    一.List遍历 Java中List遍历有三种方法来遍历泛型,主要为: 1.for循环遍历 2.iterator遍历 3.foreach遍历 package com.gmail.lsgjzhuwei; ...

  6. Android应用程序资源管理器(Asset Manager)的创建过程分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8791064 在前面一篇文章中,我们分析了And ...

  7. codevs1009

    题目地址:http://codevs.cn/problem/1009/ 分析: [TAG]FLOYD,乘法原理,高精度 [构思] 求可变换数的个数,那么就是组合数学的内容,四个原理的应用: 假如能知道 ...

  8. 智能路由——ESB

    SOA之我见 SOA已然是企业级开发的必定之路.有人会问:我们有了OOP,还须要SOA吗?好吧我承认,这个问题也困扰了我非常久.现现在我得出的结论是:OOP是OOP,SOA是SOA. OOP是指面向对 ...

  9. gradient杂谈

    工作中难免遇到某些小项目中没有设计的情况,这对于PS基础薄弱的我来说非常恐怖.无奈之下,只好自己自学UI方面的知识,但对于某些能用CSS实现的背景样式等,还是尽可能地用已经掌握的知识去实现.本文主要分 ...

  10. html5 音频

    目前,web页面上没有标准的方式来播放音频文件,大多数的音频文件是使用插件来播放,而众多的浏览器使用了不同的插件.而html5的到来,给我们提供了一个标准的方式来播放web中音频文件,用户不再为浏览器 ...