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知识不断更新)
## 大纲: ## 一.正则概述 1.正则是什么 正则就是一套规则,或者语法 2.正则的作用 让我们判断是否符合我们的的规则,或者根据规则找到符合规则的数据 3.使用场景 可以用正则判断我们输入的邮箱 ...
- TW实习日记:第18天
今天的bug没有那么多了,都是些小bug,一下就改好了.或者是接口那边数据返回的有问题,通知一下同事就ok了.主要今天是在赶功能进度,然而有一个功能模块需求里并没有写,实在是不知道要做成什么样子,真的 ...
- spark相关脚本解析
spark-shell/spark-submit/pyspark等关系如下: #spark-submit 逻辑: ########################################### ...
- 【shell 练习2】产生随机数的方法总结
一.产生随机数 ()RANDOM 产生随机数 [root@localhost ~]# echo $RANDOM [root@localhost ~]# )) #想要生成八个随机数,随便加一个八位的数字 ...
- 【Linux】Face Recognition的封装
使用虹软的人脸识别 写了一个linux下的Face Recognition的封装,当作是练习. C++的封装,结合opencv,使用方便.https://github.com/zacario-li/F ...
- Python3.5 Keras-Theano(含其他库)windows 安装环境
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.2.0-Windows-x86.execonda --version ...
- POJ 2104 K-th Number(划分树)
Description You are working for Macrohard company in data structures department. After failing your ...
- POJ 3608 Bridge Across Islands(计算几何の旋转卡壳)
Description Thousands of thousands years ago there was a small kingdom located in the middle of the ...
- 衡量生活成本:消费者价格指数(CPI, Consumer Price Index)
经济学家应该如何把经济中的许多价格加总成一个单一指数,从而能够衡量价格的总体水平呢?他们可以简单地计算所有产品与服务价格的平均值,但是这种方法的不足之处是把所有的产品与服务等同处理.由于人们购买的鸡比 ...
- 第三章 持续集成jenkins工具使用之邮件配置
1 Email Extension Plugin插件安装 持续集成很重要的一环就是及时将构建结果通知到对应的责任人,如:构建失败了,至少需要下发通知给造成本次构建失败的开发人员,如果包含自动化测试 ...