codeforces 解题报告 1009A. Game Shopping 模拟

http://codeforces.com/problemset/problem/1009/A

解题思路:

1.商店的n个游戏机按顺序排列,这里以价格代表,然后某个傻逼钱包里有m张钱,这个傻逼会依次看他钱包里的第一张钱能不能买下当前面前的游戏,能就买下,并且把第一张钱花掉(不找零,人傻钱多),依次走向下一个游戏机。计算能买多少个游戏机。

import java.util.*;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),m = sc.nextInt();
        int[] c = new int[1005];
        for(int i = 1;i <= n;i++) {
            c[i] = sc.nextInt();
        }
        int[] a = new int[1005];
        for(int i = 1;i <= m;i++) {
            a[i] = sc.nextInt();
        }
        int ans = 0,j = 1;
        for(int i = 1;i <= n;i++) {
            if(a[j] >= c[i]) {
                ans++;
                j++;
            }
        }
        System.out.println(ans);
    }
}

猜你喜欢

转载自blog.csdn.net/a912952381/article/details/81057008