hdu 5625 Clarke and chemistry

时间:2023-02-22 20:48:47
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&plus;数学

    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. uMlet建模工具

    下载:http://www.umlet.com/ 无意中发现的一款建模工具,能快速搭建数据库模型,前置安装条件是java环境. 这是我建的user模型表,2个字段name和age,2个方法getAge ...

  2. windows64系统中mysql64位绿色安装

    将下载压缩包解压到任意目录 配置安装文件: # For advice on how to change settings please see# http://dev.mysql.com/doc/re ...

  3. jQuery中append&lpar;&rpar;&comma;prepend&lpar;&rpar;与after&lpar;&rpar;&comma;before&lpar;&rpar;的区别

    在jQuery中,添加元素有append(),prepend和 after(),before()两种共四个. 根据字面意思我们可以看出他们分别是追加,添加和之前,之后,意思相近.同时他们又都有添加元素 ...

  4. Ansible系列&lpar;二&rpar;:选项和常用模块

    html { font-family: sans-serif } body { margin: 0 } article,aside,details,figcaption,figure,footer,h ...

  5. 仿9GAG制作过程(五)

    有话要说: 在做完了数据展示功能之后,就想着完善整个APP.发现现在后台非常的混乱,有好多点都不具备,比方说:图片应该有略缩图和原图,段子.评论.点赞应该联动起来,段子应该有创建时间等. 于是就重新设 ...

  6. python3 内置函数

    '''iter()和next()'''# lst = [1, 2, 3]# it = iter(lst)# print(it.__next__())# print(it.__next__())# pr ...

  7. hive表中字段显示为NULL时,HDFS文件中存储为&bsol;N

    hive数据落地到hdfs,null会默认用'\N'存储 解决方式1:利用命令(这个我没起效果) alter table adl_cici_test_fdt set serdeproperties(' ...

  8. 【C&sol;C&plus;&plus;】&colon;用C实现输出日期的阴历日子

    前言 输出阴历一直是个老大难的问题.由于阴历日子没有规律.所以这里须要做的就是通过打表的算法做到输出阴历日子,可是非常多人都不太了解原理,我这里就给大家送上了一个福利.把自己做好的基于打表的阴历的日子 ...

  9. Ajax 跨域问题&lpar;JSONP &amp&semi;&amp&semi; Access-Control-Allow-Origin&rpar;

    1.使用jsonp跨域请求 2.通过设置服务端头部跨域请求 3.设置nginx/apach 使用jsonp跨域请求 什么是Jsonp JSONP(JSON with Padding)是一个非官方的协议 ...

  10. JAVA-Unit02: Oracle字符串操作 、 Oracle数值操作 、 Oracle日期操作 、 空值操作

    Unit02: Oracle字符串操作 . Oracle数值操作 . Oracle日期操作 . 空值操作 DQL数据查询语言 查询语句基本由SELECT子句由FROM子句构成. SELECT子句指定要 ...