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 ...
随机推荐
- JSP页面中文乱码问题
$.get()方法到服务器端中文乱码 在jsp页面使用encodeURI(“中文”),在服务器端进行解码 String name = req.getParameter("name" ...
- docker学习2
今天继续学习docker! 搜索镜像 docker search centos 下载镜像 docker pull name(镜像名字) 查看镜像docker images 字段含义分析: TAG:仓库 ...
- 第一个线性回归程序(基于Jupyter)
import pandas as pdimport seaborn as snssns.set(context="notebook", style="whitegrid& ...
- 20145214实验五 Java网络编程及安全
20145214实验五 Java网络编程及安全 实验内容 1.掌握Socket程序的编写: 2.掌握密码技术的使用: 3.设计安全传输系统. 实验步骤 我的结对伙伴是 20145219 宋歌,我负责的 ...
- lintcode-197-排列序号
197-排列序号 给出一个不含重复数字的排列,求这些数字的所有排列按字典序排序后该排列的编号.其中,编号从1开始. 样例 例如,排列 [1,2,4] 是第 1 个排列. 思路 参考http://www ...
- 可用于jquery animate()方法的css属性
* backgroundPosition * borderWidth * borderBottomWidth * borderLeftWidth * borderRightWidth * border ...
- C# 知识回顾 - 你真的懂异常(Exception)吗?
你真的懂异常(Exception)吗? 目录 异常介绍 异常的特点 怎样使用异常 处理异常的 try-catch-finally 捕获异常的 Catch 块 释放资源的 Finally 块 一.异常介 ...
- SQL SERVER技术内幕之10 可编程对象
一.变量 变量用于临时保存数据值,以供在声明它们的同一批处理语句中引用.例如,以下代码先声明一个数据类型为INT的变量@i,再将它赋值为10; DECLARE @i as INT; SET @i = ...
- mysql学习之主从复制
该文使用mysql5.5 centos6.5 64位 一.主从复制的作用 1.如果主服务器出现问题,可以快速切换到从服务器. 2.对与实时性要求不高或者更新不频繁的应用可以在从服务器上执行查询操作,降 ...
- VBA练习-复杂一点
'日期添加 Sub addDate(d) Dim rg As Range, dd As Date d = Split(d, ) d = Replace(d, ".", " ...