zoukankan      html  css  js  c++  java
  • pat1048. Find Coins (25)

    1048. Find Coins (25)

    时间限制
    50 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However, there was a special requirement of the payment: for each bill, she could only use exactly two coins to pay the exact amount. Since she has as many as 105 coins with her, she definitely needs your help. You are supposed to tell her, for any given amount of money, whether or not she can find two coins to pay for it.

    Input Specification:

    Each input file contains one test case. For each case, the first line contains 2 positive numbers: N (<=105, the total number of coins) and M(<=103, the amount of money Eva has to pay). The second line contains N face values of the coins, which are all positive numbers no more than 500. All the numbers in a line are separated by a space.

    Output Specification:

    For each test case, print in one line the two face values V1 and V2 (separated by a space) such that V1 + V2 = M and V1 <= V2. If such a solution is not unique, output the one with the smallest V1. If there is no solution, output "No Solution" instead.

    Sample Input 1:
    8 15
    1 2 8 7 2 4 11 15
    
    Sample Output 1:
    4 11
    
    Sample Input 2:
    7 14
    1 8 7 2 4 11 15
    
    Sample Output 2:
    No Solution
    

    提交代码

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<queue>
     6 #include<vector>
     7 #include<cmath>
     8 #include<string>
     9 #include<map>
    10 #include<set>
    11 using namespace std;
    12 int line[100005];
    13 int main(){
    14     //freopen("D:\INPUT.txt","r",stdin);
    15     int n,m;
    16     scanf("%d %d",&n,&m);
    17     int i,j;
    18     for(i=0;i<n;i++){
    19         scanf("%d",&line[i]);
    20     }
    21     sort(line,line+n);
    22 
    23     /*for(i=0;i<n;i++){
    24         cout<<i<<" "<<line[i]<<endl;
    25     }*/
    26 
    27     i=0;
    28     j=n-1;
    29     while(i<j){
    30         if(line[i]+line[j]>m){
    31             j--;
    32             continue;
    33         }
    34         if(line[i]+line[j]<m){
    35             i++;
    36             continue;
    37         }
    38         break;
    39     }
    40     if(i<j){
    41         printf("%d %d
    ",line[i],line[j]);
    42     }
    43     else{
    44         printf("No Solution
    ");
    45     }
    46     return 0;
    47 }
  • 相关阅读:
    [IT学习]Python pandas 学习
    [IT学习]Python 小项目 通讯录 思路
    [IT学习]学习Python过程需要记忆的一些坑
    【线性结构】A1074Reversing Linked List
    【线性结构】一元多项式的乘法与加法运算
    【线性结构】两个有序链表序列的合并
    C/C++中函数参数传递的三种情况(p *p &p)
    解决pip安装包的时候超时失败(很多红色错误)的问题
    A1012The Best Rank
    B1015/A1062德才论
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4771374.html
Copyright © 2011-2022 走看看