1048. Find Coins (25)

本文介绍了一个支付场景下的问题——FindCoins。在这个问题中,需要从大量不同面额的硬币中找出两个硬币来支付特定金额。文章详细阐述了如何通过编程解决这一问题,并给出了具体的代码实现。

1048. Find Coins (25)

 

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
注意coin的两个值相等的情况!
 
参考代码:
 
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
vector<int> arr(100001);
int N,M;
int main()
{
    scanf("%d%d",&N,&M);
    for(int i=0;i<N;i++){
        int temp;
        scanf("%d",&temp);
        arr[temp]++;
    }
    for(int i=1;i<=M;i++){
        if(arr[i]>0){
            if(arr[M-i]>0){
                if(2*i!=M){
                    cout<<i<<" "<<M-i;
                    return 0;
                }else if(arr[i]>1){
                    cout<<i<<" "<<i;
                    return 0;
                }
            }
        }
    }
    cout<<"No Solution";
    return 0;
}

from bs4 import BeautifulSoup import requests import lxml import openpyxl import os def get_html(url,headers,data): try: response = requests.get(url, headers=headers, params=data) if response.status_code == 200: return response.text else: print('请求失败') except Exception as e: print(e) def save_data(html): soup=BeautifulSoup(html,'lxml') node=soup.find_all('table') for sub_node in node: title=sub_node.find_all('h1')[2].get('title') likes=sub_node.find_all('span',{'class':'video-like-info video-toolbar-item-text'})[0].string coins=sub_node.find_all('span',{'class':'video-coin-info video-toolbar-item-text'})[0].string favorites=sub_node.find_all('span',{'class':'video-fav-info video-toolbar-item-text'})[0].string shares=sub_node.find_all('span',{'class':'video-share-info video-toolbar-item-text'})[0].string description=sub_node.find_all('span',{'class':'desc-info-text'})[0].string print(title, likes, coins, favorites, shares, description) sheet.append([title, likes, coins, favorites, shares, description]) if __name__ == "__main__": path='d:\\video' if not os.path.exists(path): os.mkdir(path) os.chdir(path) wb = openpyxl.Workbook() sheet = wb.active sheet.append(['标题', '点赞人数', '投币人数', '收藏人数', '转发人数','视频介绍']) url ='https://search.bilibili.com/all?vt=68706038&keyword=python&page=''' headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36' } data={ 'page':0 } for page in range(0,11): data['page'] = page html = get_html(url,headers,data) save_data(html) wb.save('video.xlsx') 请将我的代码完善,我想要实现前十页视频爬取的相关内容
最新发布
06-13
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值