POJ-3021 e-Coins(广搜)
来源:互联网 发布:贷款抢单软件 编辑:程序博客网 时间:2024/06/11 19:04
e-Coins
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 699 Accepted: 348
Description
At the Department for Bills and Coins, an extension of today's monetary system has newly been proposed, in order to make it fit the new economy better. A number of new so called e-coins will be produced, which, in addition to having a value in the normal sense of today, also have an InfoTechnological value. The goal of this reform is, of course, to make justice to the economy of numerous dotcom companies which, despite the fact that they are low on money surely have a lot of IT inside. All money of the old kind will keep its conventional value and get zero InfoTechnological value.
To successfully make value comparisions in the new system, something called the e-modulus is introduced. This is calculated as SQRT(X*X+Y*Y), where X and Y hold the sums of the conventional and InfoTechnological values respectively. For instance, money with a conventional value of $3 altogether and an InfoTechnological value of $4 will get an e-modulus of $5. Bear in mind that you have to calculate the sums of the conventional and InfoTechnological values separately before you calculate the e-modulus of the money.
To simplify the move to e-currency, you are assigned to write a program that, given the e-modulus that shall be reached and a list of the different types of e-coins that are available, calculates the smallest amount of e-coins that are needed to exactly match the e-modulus. There is no limit on how many e-coins of each type that may be used to match the given e-modulus.
To successfully make value comparisions in the new system, something called the e-modulus is introduced. This is calculated as SQRT(X*X+Y*Y), where X and Y hold the sums of the conventional and InfoTechnological values respectively. For instance, money with a conventional value of $3 altogether and an InfoTechnological value of $4 will get an e-modulus of $5. Bear in mind that you have to calculate the sums of the conventional and InfoTechnological values separately before you calculate the e-modulus of the money.
To simplify the move to e-currency, you are assigned to write a program that, given the e-modulus that shall be reached and a list of the different types of e-coins that are available, calculates the smallest amount of e-coins that are needed to exactly match the e-modulus. There is no limit on how many e-coins of each type that may be used to match the given e-modulus.
Input
A line with the number of problems n (0 < n<=100), followed by n times:
- A line with the integers m (0 < m<=40) and S (0 < S<=300), where m indicates the number of different e-coin types that exist in the problem, and S states the value of the e-modulus that shall be matched exactly.
- m lines, each consisting of one pair of non-negative integers describing the value of an e-coin. The first number in the pair states the conventional value, and the second number holds the InfoTechnological value of the coin.
Output
The output consists of n lines. Each line contains either a single integer holding the number of coins necessary to reach the specified e-modulus S or, if S cannot be reached, the string "not possible".
Sample Input
3 2 5 0 2 2 0 3 20 0 2 2 0 2 1 3 5 3 0 0 4 5 5
Sample Output
not possible 10 2
Hint
The illustration examplifies adding 8 coins of conventional value 2 and InfoTechnological value 1, and 2 coins with pure InfoTechnological value 2. The e-modulus is of course 20 as SQRT((8*2+2*0)^2+(8*1+2*2)^2)=SQRT(16^2+12^2)=20
题目中输入m组数据,表示一步可以走的m种情况。
思路:与一边的广搜题目差不多,只要读懂题意就好,只是广搜向外拓展时是枚举输入的m种情况
图没有界限,但是要保证拓展的点到(0,0)点的距离小于等于n;
代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<queue>using namespace std;struct node{ int x; int y; int step;};int u[200],v[200],m,n;int book[400][400];void bfs(){ node now,tmp; queue<node> q; now.x=0; now.y=0; now.step=0; book[0][0]=1; q.push(now); while(!q.empty()) { now=q.front(); q.pop(); if(sqrt(now.x*now.x+now.y*now.y)==n) { printf("%d\n",now.step); return ; } for(int i=0;i<m;i++)//枚举m种情况 { int tx=now.x+u[i]; int ty=now.y+v[i]; if(tx*tx+ty*ty<=n*n&&book[tx][ty]==0)//保证(tx,ty)到(0,0)的距离<=n { book[tx][ty] = 1; tmp.x = tx; tmp.y = ty; tmp.step = now.step + 1;//步数 q.push(tmp); } } } printf("not possible\n");}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&m,&n);//m种走法,n是距离(0,0)的距离 for(int i=0 ; i<m ;i++) scanf("%d%d",&u[i],&v[i]); memset(book,0,sizeof(book));//标记是否走过 bfs(); } return 0;}
阅读全文
0 0
- POJ-3021 e-Coins(广搜)
- POJ-3021-e-Coins
- e-Coins POJ
- POJ 3984-----E - 广搜记录路径 基础
- e-Coins
- 广搜 poj 3126
- POJ 3126 广搜
- POJ 2049 广搜
- 广搜poj.3009
- POJ 2243 广搜
- poj-2251 广搜
- poj 3414 广搜
- poj 3278 广搜
- POJ 3087 广搜
- POJ 1915 双向广搜
- 广搜1 poj 2243
- POJ 3126 素数+广搜
- POJ 1426 广搜BFS
- 左神面试算法整理--并归求小和
- vue.js几种不同组件(页面)间传值的方式
- @Temporal——指定查询Date格式
- ros机器人操作系统
- poj 1961 Period(kmp)
- POJ-3021 e-Coins(广搜)
- json工具类
- CPU核数和多线程的关系
- ActiveMQ在数据中的表说明(queue,durable topic)
- Git LF和CRLF问题解决记录
- 正则表达式和通配符的区别
- echo命令有趣的颜色参数
- Android通过Enable动态设置color—color@res@Android
- 微信的图片查看