AYIT2017暑假集训第三周周三赛 A
来源:互联网 发布:centos7修改远程端口 编辑:程序博客网 时间:2024/05/18 02:57
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.
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.
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".
3 2 5 0 2 2 0 3 20 0 2 2 0 2 1 3 5 3 0 0 4 5 5
not possible 10 2
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
题目大概意思就是给你几个点和一个固定值,从中挑选进行组合看什么时候能等于那个值
#include<stdio.h>#include<string.h>struct note{ int x,y,z,s;} l[100000];int n,m,t,flag,sum;int x1[1000],y1[1000],book[450][450];void bfs(){ int head=1,tail=2,i; l[head].x=0; l[head].y=0; l[head].z=0; l[head].s=0; while(head<tail) { if(l[head].z==m*m) { flag=1; sum=l[head].s; break; } for(i=0; i<n; i++) { int tx=l[head].x+x1[i]; int ty=l[head].y+y1[i]; int tz=tx*tx+ty*ty; if(tz<=m*m) { if(book[tx][ty]==0) { l[tail].z=tz; l[tail].x=tx; l[tail].y=ty; book[tx][ty]=1; l[tail].s=l[head].s+1; tail++; } } } head++; }}int main(){ int i,j; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(i=0; i<n; i++) scanf("%d%d",&x1[i],&y1[i]); flag=0; sum=0; memset(book,0,sizeof(book)); book[0][0]=1; bfs(); if(flag) printf("%d\n",sum); else printf("not possible\n"); }}
阅读全文
0 0
- AYIT2017暑假集训第三周周三赛 A
- AYIT2017暑假集训第二周周三赛 A
- AYIT2017暑假集训第二周周三赛 B
- AYIT2017暑假集训第二周周三赛 C
- AYIT2017暑假集训第二周周三赛 G
- AYIT2017暑假集训第二周周三赛 D
- AYIT2017暑假集训第二周周三赛 E
- 暑假集训第三周周三赛 STL A - So easy 判断集合
- 暑假集训第三周周三赛 STL D - 产生冠军
- 暑假集训第三周周三赛 STL E - Gunner 射鸟
- 暑假集训第三周周三赛 STL F - 水果
- 暑假集训第三周周三赛 STL G - Intelligent IME
- 暑假集训第三周周三赛 STL C - Strange Class 字符相同 SC数
- 暑假集训大二第一周周三赛 A仙人掌的残影
- 暑假集训第三周周六赛 搜索 B - Red and Black红黑瓷片
- 暑假集训第三周周六赛 搜索 E - N皇后问题
- 暑假集训第三周周六赛 搜索 F - Oil Deposits 油块
- 暑假集训第三周周六赛 STL D - 胜利大逃亡
- 数据结构之排序算法
- NYOJ-236
- 对数组进行冒泡排序,使用comparable接口实现
- 1076. Forwards on Weibo (30)
- UVA 1630 Folding——区间DP(记忆化搜索)
- AYIT2017暑假集训第三周周三赛 A
- SDNU 1519.lmh’s Function 找循环节
- 变量类型转换
- jvm类加载机制概述
- 【Java编程】面向对象基础
- 一分钟读懂低功耗蓝牙(BLE)MTU交换数据包
- 20-service之$watch
- jQuery Mobile基础教程(一)
- 公安大数据应用之情报分析与关联挖掘