hdoj--5625--Clarke and chemistry(枚举)
Clarke and chemistry
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
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
a
and b
If there are multiple answers, print the smallest one,
a
is smallest then b
is smallest. Otherwise print NO.
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
2 3
NO Hint:
The first test case, $a=2, b=3$ can make equation right.
The second test case, no any answer.
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int A[27],B[27],C[27];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
char op[2];
bool flag=true;
int d,maxx=0;
memset(B,0,sizeof(B));
memset(C,0,sizeof(C));
memset(A,0,sizeof(A));
for(int i=0;i<a;i++)
{
scanf("%s%d",op,&d);
A[op[0]-'A']=d;
}
for(int i=0;i<b;i++)
{
scanf("%s%d",op,&d);
B[op[0]-'A']=d;
}
for(int i=0;i<c;i++)
{
scanf("%s%d",op,&d);
C[op[0]-'A']=d;
// maxx=max(maxx,d/A[op[0]-'A']);
// maxx=max(maxx,d/B[op[0]-'A']);
}
int i,j,k;
int min,x,y;
for(i=1;i<=1000&&flag;i++)
for(j=1;j<=1000;j++)
{
int s;
for(s=0;s<26;s++)
{
x=i*A[s]+j*B[s];
y=C[s];
if(x==y)
continue;
else break;
}
if(s==26) flag=false;
if(!flag) break;
}
if(!flag) printf("%d %d\n",i-1,j);
else printf("NO\n");
}
return 0;
}
hdoj--5625--Clarke and chemistry(枚举)的更多相关文章
- hdu  5625 Clarke and chemistry
		
Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned i ...
 - BestCoder Round #72
		
由于第一次打,只能在div2打.(这么好的机会还没AK真是丢人) T1 Clarke and chemistry 枚举题不解释(我不会告诉你我上来WA了四发的) T2 Clarke and point ...
 - hdu 5625
		
Clarke and chemistry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
 - BestCoder Round #72 (div.2)
		
后面的题目补不懂了 暴力 1001 Clarke and chemistry 这题也把我搞死了..枚举系数判断就行了 #include <cstdio> #include <algo ...
 - 二进制枚举 + 容斥定理(hdoj 4336 )
		
hdoj 4336 http://acm.hdu.edu.cn/showproblem.php?pid=4336 这是一道关于概率与期望的问题,其中 期望 = 1 / 概率 容斥原理 P = ...
 - 枚举+贪心 HDOJ 4932 Miaomiao's Geometry
		
题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...
 - HDOJ/HDU 1015 Safecracker(枚举、暴力)
		
Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...
 - HDOJ(HDU)  1562  Guess the number(水题,枚举就行)
		
Problem Description Happy new year to everybody! Now, I want you to guess a minimum number x betwwn ...
 - hdoj 4445 Crazy Tank 物理题/枚举角度1
		
Crazy TankTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
 
随机推荐
- SQL基本操作——日期函数
			
SQL日期:当我们处理日期时,最难的任务恐怕是确保所插入的日期的格式,与数据库中日期列的格式相匹配.只要数据包含的只是日期部分,运行查询就不会出问题.但是,如果涉及时间,情况就有点复杂了.在讨论日期查 ...
 - python调用java API
			
JPype documentation JPype is an effort to allow python programs full access to java class libraries. ...
 - WCF开发的流程-服务端和客户端之间的通讯(内含demo讲解)
			
讲解技术之前,恳请博友让我说几句废话.今天是我第一在博客园发布属于自己原创的博文(如有雷同,那是绝对不可能的事,嘿嘿).之前一直是拜读各位博友的大作,受益匪浅的我在这对博友们说声谢谢,谢谢你们的共享! ...
 - DECLARE_MESSAGE_MAP( )
			
DECLARE_MESSAGE_MAP( ) 说明: 你的程序中的每一个CCmdTarget的派生类都可以提供一个消息映射以处理消息.在你的类声明的末尾使用DECLARE_MESSAGE_MAP宏.然 ...
 - VMware Workstation Pro 15 for Windows下载与安装
			
VMware Workstation Pro 15 for Windows下载与安装 一.下载 下载地址:https://my.vmware.com/cn/web/vmware/details?dow ...
 - API 接口监控产品全新改版,免费开放全部功能
			
作为 EOLINKER 研发管理体系的重要一环,EOLINKER 接口监控即 AMT 产品将在 3月4日 迎来全新变化,AMT 产品将正式命名为 EOLINKER-API Beacon --API-烽 ...
 - 1、DataGridView
			
DataGridView赋值后 通过RowPostPaint事件绘制行号 private void AddXh() { DataGridViewTextBoxColumn col = new Data ...
 - swap() 函数实现的方法
			
swap()函数总结: 一.利用临时变量 1.引用(交换任意类型) template <typename T> void swap(T& x,T& y) { T tmp; ...
 - 六、Scrapy中Download Middleware的用法
			
本文转载自: https://scrapy-chs.readthedocs.io/zh_CN/latest/topics/downloader-middleware.html https://doc. ...
 - Flask - Flask的蓝图(BluePrint)
			
目录 Flask - Flask的蓝图(BluePrint) 一. 初始Flask蓝图 进阶Flask蓝图 使用蓝图做一个增删改查 1.使用蓝图进行web应用搭建: 2.使用Flask蓝图,查看学生信 ...