zoukankan      html  css  js  c++  java
  • Codeforces 463A. Caisa and Sugar

    Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.

    Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But that's not all. The supermarket has very unusual exchange politics: instead of cents the sellers give sweets to a buyer as a change. Of course, the number of given sweets always doesn't exceed 99, because each seller maximizes the number of dollars in the change (100 cents can be replaced with a dollar).

    Caisa wants to buy only one type of sugar, also he wants to maximize the number of sweets in the change. What is the maximum number of sweets he can get? Note, that Caisa doesn't want to minimize the cost of the sugar, he only wants to get maximum number of sweets as change. 

    Input

    The first line contains two space-separated integers n, s (1 ≤ n, s ≤ 100).

    The i-th of the next n lines contains two integers xiyi (1 ≤ xi ≤ 100; 0 ≤ yi < 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.

    Output

    Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.

    题目很水,但是理解错了。。。其实糖果就买一个就好

    #include <cstdio>
    #include <cctype>
    #include <stdlib.h>
    #include <iostream>
    #include <cmath>
    #include <iomanip>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <map>
    
    using namespace std;
    typedef long long LL;
    
    
    int n,s;
    int main()
    {
      // freopen("test.in","r",stdin);
      cin >> n >> s;
      int res = -1;
      for (int i=0;i<n;i++){
        int dol,cent;
        cin >> dol >> cent;
        if (dol > s || (dol == s && cent > 0)){
          continue;
        }
        int sweet = -1;
        int price = 100*dol + cent;
        // while (price * num <= 100 * s){
        //
        //   // cout << (100*s - price*num) % 100 << endl;
        //   sweet = max(sweet,(100*s - price*num) % 100);
        //   num ++;
        // }
        sweet = (100*s - price) % 100;
        res = max(res,sweet);
      }
      cout << res;
      return 0;
    }
    View Code
  • 相关阅读:
    switch语句(上)(转载)
    MSIL实用指南-生成if...else...语句
    Docker 部署Jira8.1.0
    K8S从入门到放弃系列-(13)Kubernetes集群mertics-server部署
    K8S踩坑篇-master节点作为node节点加入集群
    K8S从入门到放弃系列-(12)Kubernetes集群Coredns部署
    K8S从入门到放弃系列-(11)kubernetes集群网络Calico部署
    K8S从入门到放弃系列-(10)kubernetes集群之kube-proxy部署
    K8S从入门到放弃系列-(9)kubernetes集群之kubelet部署
    K8S从入门到放弃系列-(8)kube-apiserver 高可用配置
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/6880317.html
Copyright © 2011-2022 走看看