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 ...
随机推荐
- JavaWeb项目中引入spring框架
主要步骤有以下3步: 1:下载spring的jar包2:在项目中web.xml中添加spring配置3:bean配置文件-applicationContext.xml 1:引入包,这个就不说了,官网下 ...
- sql中表变量
今天在公司看sql优化的文章的时候,提到了表变量,做下笔记. 表变量 顺便复习下临时表.
- Resources.getResourceAsReader 报空指针
1.maven项目中 可能未编译 导致找不到, 解决方法:mvn clean install -DskipTests -X 编译一下项目 2.可能在 Resources.getResourceAs ...
- GeckoWebBrowser设置cookie
var uri = new Uri("http://www.aa.com"); //often cookies are stored on domain level, so &qu ...
- Android—修改button属性
一般安卓里的普通按钮控件灰灰的,比较单调,我们可以给按钮加上背景图片,或者自定义按钮的圆角,颜色等属性. 下面用代码举例: <Button android:id="@+id/reset ...
- Maximum Value(unique函数,lower_bound()函数,upper_bound()函数的使用)
传送门 在看大佬的代码时候遇到了unique函数以及二分查找的lower_bound和upper_bound函数,所以写这篇文章来记录以备复习. unique函数 在STL中unique函数是一个去重 ...
- ELK6 收集不同来源的日志并做区分
https://blog.csdn.net/u010871982/article/details/79035317 使用filebeat替代logstash进行日志采集 https://blog.cs ...
- 亚马逊免费服务器搭建Discuz!论坛过程(四)
上述命令还可能因缺少包引发其他错误: 如果出错则安装对应的包即可. 以下供参考: yum install libxml2 yum install libxml2-devel -y yum instal ...
- everyday two problems / 3.1
T1.string 题意: 给定由小写字母组成的长度为 n 的字符串 将其所有 n * (n + 1) / 2 个子串按字典序排序 输出第 k 个子串 k > (n * (n + 1) / 2) ...
- hdu_1012_u Calculate e_201310121519
u Calculate eTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...