POJ 2256 Artificial Intelligence?

本文提供了一个简单的算法,用于解决给定电压、电流或功率的物理电路问题,并通过实例展示了如何计算未知参数。

原题地址:http://poj.org/problem?id=2256


Artificial Intelligence?
Time Limit:1000MS
Memory Limit:65536K




Description

Physics teachers in high school often think that problems given as text are more demanding than pure computations. After all, the pupils have to read and understand the problem first!
So they don't state a problem like "U=10V, I=5A, P=?" but rather like "You have an electrical circuit that contains a battery with a voltage of U=10V and a light-bulb. There's an electrical current of I=5A through the bulb. Which power is generated in the bulb?".
However, half of the pupils just don't pay attention to the text anyway. They just extract from the text what is given: U=10V, I=5A. Then they think: "Which formulae do I know? Ah yes, P=U*I. Therefore P=10V*5A=500W. Finished."
OK, this doesn't always work, so these pupils are usually not the top scorers in physics tests. But at least this simple algorithm is usually good enough to pass the class. (Sad but true.)
Today we will check if a computer can pass a high school physics test. We will concentrate on the P-U-I type problems first. That means, problems in which two of power, voltage and current are given and the third is wanted.

Your job is to write a program that reads such a text problem and solves it according to the simple algorithm given above.

Input

The first line of the input will contain the number of test cases.
Each test case will consist of one line containing exactly two data fields and some additional arbitrary words. A data field will be of the form I=xA, U=xV or P=xW, where x is a real number. Directly before the unit (A,V or W) one of the prefixes m (milli), k (kilo) and M (Mega) may also occur. To summarize it: Data fields adhere to the following grammar:
DataField ::= Concept '=' RealNumber [Prefix] Unit
Concept   ::= 'P' | 'U' | 'I'

Prefix    ::= 'm' | 'k' | 'M'

Unit      ::= 'W' | 'V' | 'A'

Additional assertions:
  • The equal sign ('=') will never occur in an other context than within a data field.
  • There is no whitespace (tabs,blanks) inside a data field.
  • Either P and U, P and I, or U and I will be given.

Output

For each test case, print three lines:
  • a line saying "Problem #k" where k is the number of the test case
  • a line giving the solution (voltage, power or current, dependent on what was given), written without a prefix and with two decimal places as shown in the sample output
  • a blank line

Sample Input

3
If the voltage is U=200V and the current is I=4.5A, which power is generated?
A light-bulb yields P=100W and the voltage is U=220V. Compute the current, please.
bla bla bla lightning strike I=2A bla bla bla P=2.5MW bla bla voltage?

Sample Output

 
 
 

Problem #1
P=900.00W


Problem #2
I=0.45A


Problem #3
U=1250000.00V

由于开始以为是m是million的意思,WA了好多次,郁闷........

AC代码如下

/************************************************************************** * Problem: POJ 2256 Artificial Intelligence? * Copyright 2011 by Yan * DATE: * E-Mail: yming0221@gmail.com ************************************************************************/ #include <stdio.h> char cache[2000]; char op1[50]; char op2[50]; double dop1,dop2; int len; void get_op(int p1,int p2) { int index=p1; int op_index=0; int i; char tmp;/*存放单位字符*/ while(cache[++index]!='A'&& cache[index]!='W'&& cache[index]!='V') { op1[op_index++]=cache[index]; } op1[op_index]='\0'; tmp=op1[op_index-1]; if(tmp=='m'||tmp=='k'||tmp=='M') op1[op_index-1]='\0';/*从字符串中取出单位*/ sscanf(op1,"%lf",&dop1); switch (tmp) { case 'k':dop1=dop1*1000.0;break; case 'm':dop1=dop1*0.001;break; case 'M':dop1=dop1*1000000.0;break; } index=p2; op_index=0; while(cache[++index]!='A'&& cache[index]!='W'&& cache[index]!='V') { op2[op_index++]=cache[index]; } op2[op_index]='\0'; tmp=op2[op_index-1]; if(tmp=='m'||tmp=='k'||tmp=='M') op1[op_index-1]='\0';/*从字符串中取出单位*/ sscanf(op2,"%lf",&dop2); switch (tmp) { case 'k':dop2=dop2*1000.0;break; case 'm':dop2=dop2*0.001;break; case 'M':dop2=dop2*1000000.0;break; } } int main() { /*freopen("input","r",stdin);*/ int n,i,j; int index[2];/*存放两个等号的位置*/ int cnt; double ans; scanf("%d ",&n); for(i=1;i<=n;i++) { gets(cache); /*puts(cache);*/ len=strlen(cache); cnt=0; for(j=0;j<len;j++) { if(cache[j]=='=') index[cnt++]=j; if(cnt==2) break; }/*扫描到两个等号*/ get_op(index[0],index[1]);/*获取操作数和操作*/ printf("Problem #%d\n",i); if( (cache[index[0]-1]=='U'&&cache[index[1]-1]=='I') || (cache[index[0]-1]=='I'&&cache[index[1]-1]=='U')) { printf("P=%.2fW\n\n",dop1*dop2); } else if( (cache[index[0]-1]=='P'&&cache[index[1]-1]=='I') || (cache[index[0]-1]=='I'&&cache[index[1]-1]=='P')) { if(cache[index[0]-1]=='P') printf("U=%.2fV\n\n",dop1/dop2); else printf("U=%.2fV\n\n",dop2/dop1); } else if( (cache[index[0]-1]=='U'&&cache[index[1]-1]=='P') || (cache[index[0]-1]=='P'&&cache[index[1]-1]=='U')) { if(cache[index[0]-1]=='P') printf("I=%.2fA\n\n",dop1/dop2); else printf("I=%.2fA\n\n",dop2/dop1); } } return 0; }


本项目采用C++编程语言结合ROS框架构建了完整的双机械臂控制系统,实现了Gazebo仿真环境下的协同运动模拟,并完成了两台实体UR10工业机器人的联动控制。该毕业设计在答辩环节获得98分的优异成绩,所有程序代码均通过系统性调试验证,保证可直接部署运行。 系统架构包含三个核心模块:基于ROS通信架构的双臂协调控制器、Gazebo物理引擎下的动力学仿真环境、以及真实UR10机器人的硬件接口层。在仿真验证阶段,开发了双臂碰撞检测算法和轨迹规划模块,通过ROS控制包实现了末端执行器的同步轨迹跟踪。硬件集成方面,建立了基于TCP/IP协议的实时通信链路,解决了双机数据同步和运动指令分发等关键技术问题。 本资源适用于自动化、机械电子、人工智能等专业方向的课程实践,可作为高年级课程设计、毕业课题的重要参考案例。系统采用模块化设计理念,控制核心与硬件接口分离架构便于功能扩展,具备工程实践能力的学习者可在现有框架基础上进行二次开发,例如集成视觉感知模块或优化运动规划算法。 项目文档详细记录了环境配置流程、参数调试方法和实验验证数据,特别说明了双机协同作业时的时序同步解决方案。所有功能模块均提供完整的API接口说明,便于使用者快速理解系统架构并进行定制化修改。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
【微电网】【创新点】基于非支配排序的蜣螂优化算法NSDBO求解微电网多目标优化调度研究(Matlab代码实现)内容概要:本文围绕基于非支配排序的蜣螂优化算法(NSDBO)在微电网多目标优化调度中的应用展开研究,提出了一种改进的智能优化算法以解决微电网系统中经济性、环保性和能源效率等多重目标之间的权衡问题。通过引入非支配排序机制,NSDBO能够有效处理多目标优化中的帕累托前沿搜索,提升解的多样性和收敛性,并结合Matlab代码实现仿真验证,展示了该算法在微电网调度中的优越性能和实际可行性。研究涵盖了微电网典型结构建模、目标函数构建及约束条件处理,实现了对风、光、储能及传统机组的协同优化调度。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事微电网、智能优化算法应用的工程技术人员;熟悉优化算法与能源系统调度的高年级本科生亦可参考。; 使用场景及目标:①应用于微电网多目标优化调度问题的研究与仿真,如成本最小化、碳排放最低与供电可靠性最高之间的平衡;②为新型智能优化算法(如蜣螂优化算法及其改进版本)的设计与验证提供实践案例,推动其在能源系统中的推广应用;③服务于学术论文复现、课题研究或毕业设计中的算法对比与性能测试。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注NSDBO算法的核心实现步骤与微电网模型的构建逻辑,同时可对比其他多目标算法(如NSGA-II、MOPSO)以深入理解其优势与局限,进一步开展算法改进或应用场景拓展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值