hdu 5625
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
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}^*
.
, 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
)
and b
. If there are multiple answers, print the smallest one, a
is smallest then b
is smallest. Otherwise print NO.
NO
Hint:
The first test case, $a=2, b=3$ can make equation right.
The second test case, no any answer.
#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的更多相关文章
- hdu 5625 Clarke and chemistry
Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned i ...
- HDU 2078 复习时间
http://acm.hdu.edu.cn/showproblem.php?pid=2078 Problem Description 为了能过个好年,xhd开始复习了,于是每天晚上背着书往教室跑.xh ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
随机推荐
- Python全栈 正则表达式(re模块正则接口全方位详解)
re模块是Python的标准库模块 模块正则接口的整体模式 re.compile 返回regetx对象 finditer fullmatch match search 返回 match对象 match ...
- [HNOI2018]寻宝游戏(题解转载自别处)
题解(自别处转载): Luogu CSDN 这题关键是将运算符也替换成0,1 然后在运算符与原串混杂里找规律. 而且替换的方式也有所要求,考场上两种替换方式都要尝试. #include <bit ...
- 【转】Backbone.js学习笔记(一)
文章转自: http://segmentfault.com/a/1190000002386651 基本概念 前言 昨天开始学Backbone.js,写篇笔记记录一下吧,一直对MVC模式挺好奇的,也对j ...
- js经典试题之闭包
js经典试题之闭包 1:以下代码输出的结果是? function Foo(){ var i=0; return function(){ document.write(i++); } } var f1= ...
- Repair the Wall (贪心)
Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful ...
- TCP系列02—连接管理—1、三次握手与四次挥手
一.TCP连接管理概述 正如我们在之前所说TCP是一个面向连接的通信协议,因此在进行数据传输前一般需要先建立连接(TFO除外),因此我们首先来介绍TCP的连接管理. 通常一次完整的TCP数据传输一般包 ...
- LoadRunner中执行命令行
在LoadRunner可以使用函数system()来调用系统指令,结果同在批处理里执行一样,但是system()有个缺陷:无法获取命令的返回结果. 也许可以用`echo command > fi ...
- 把jar包加入本地maven库内
1首先,在项目的pom.xml文件中加入 <dependency><groupId>taobao-alidayu</groupId> //名字随便取不要跟已有的重 ...
- 【log4net】- 非常完善的Log4net详细说明
1.概述 log4net是.Net下一个非常优秀的开源日志记录组件.log4net记录日志的功能非常强大.它可以将日志分不同的等级,以不同的格式,输出到不同的媒介.本文主要是介绍如何在Visual S ...
- codesandbox
codesandbox https://codesandbox.io https://codesandbox.io/dashboard https://codesandbox.io/dashboard ...