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 }
  • 相关阅读:
    专门针对初学者的Node.js教程
    windows版的node.js简单示例
    bzoj 1003: [ZJOI2006]物流运输【spfa+dp】
    bzoj 3573: [Hnoi2014]米特运输【树形dp+瞎搞】
    bzoj 1082: [SCOI2005]栅栏【二分+dfs】
    bzoj 2440: [中山市选2011]完全平方数【莫比乌斯函数+二分】
    bzoj 1049: [HAOI2006]数字序列【dp+二分+瞎搞】
    bzoj 2588: Spoj 10628. Count on a tree【主席树+倍增】
    bzoj 4551: [Tjoi2016&Heoi2016]树【并查集】
    bzoj 4310: 跳蚤【后缀数组+st表+二分+贪心】
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4771374.html
Copyright © 2011-2022 走看看