HDU5090 Game with Pearls(贪心)
来源:互联网 发布:软件企业资质证书 编辑:程序博客网 时间:2024/06/08 13:52
Game with Pearls
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5090
解题思路:
贪心: 将N个管子按管子中的珍珠数量升序排序,则满足条件的时候第i个管子应该有i个珍珠。
每个管子开始遍历,如果第i个管子有i个珍珠,则进行下一次循环;
如果小于i个珍珠,则加上k个珍珠,重新按升序排序;
如果大于i个珍珠,则说明不满足条件 .
AC代码:
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int main(){ int T,a[110]; scanf("%d",&T); while(T--){ int i,n,k,flag = 1; scanf("%d%d",&n,&k); for(i = 1; i <= n; i++) scanf("%d",&a[i]); sort(a+1,a+n+1); for(i = 1; i <= n; i++){ if(a[i] == i) continue; else{ while(a[i] < i){ a[i] += k; sort(a+i,a+n+1); if(a[i] == i) break; } if(a[i] == i) continue; else{ flag = 0; break; } } } if(flag) printf("Jerry\n"); else printf("Tom\n"); } return 0;}
1 0
- HDU5090 Game with Pearls(贪心)
- HDU 5090 Game with Pearls(贪心)
- hdu 5090 Game with Pearls 贪心
- HDU 5090 Game with Pearls(贪心, 二部图最大匹配)
- HDU 5090 Game with Pearls【贪心||模拟||二分匹配】
- D - Game with Pearls
- Game with Pearls
- D.Game with Pearls
- hdu 5090 Game with Pearls
- hdu 5090 Game with Pearls
- HDU 5090 Game with Pearls
- HDU 5090 Game with Pearls
- HDU 5090 - Game with Pearls
- HDU-5090--Game with Pearls
- HDU 5090 Game with Pearls
- HDU 5090 Game with Pearls
- Hdu 5090 Game with Pearls(二分匹配)
- HDU 5090 Game with Pearls(二分匹配)
- C++名称查找与ADL
- poj 3190 Stall Reservations1
- 从头认识C—break和continue语句
- 数字图像处理之作业2
- Android 高仿微信6.0主界面 带你玩转切换图标变色
- HDU5090 Game with Pearls(贪心)
- JAVA基础---1
- Kettle 增量更新设计技巧
- PAT Advanced Level (1081~1087)
- Hadoop学习笔记(1)安装配置与运行
- 虚拟机自省XenAccess和vmitools
- 网页游戏开发整理——开场篇
- iOS 很全的小技巧集合
- (每日算法)LeetCode---Search a 2D Matrix(查找元素是否存在)