是18号做的题啦,现在才把报告补上是以前不重视报告的原因吧,不过现在真的很喜欢写报告,也希望能写一些有意义的东西出来。
A - Dragons

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito's strength equals s.

If Kirito starts duelling with the i-th (1 ≤ i ≤ n) dragon and Kirito's strength is not greater than the dragon's strength xi, then Kirito loses the duel and dies. But if Kirito's strength is greater than the dragon's strength, then he defeats the dragon and gets a bonus strength increase by yi.

Kirito can fight the dragons in any order. Determine whether he can move on to the next level of the game, that is, defeat all dragons without a single loss.

Input

The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it.

Output

On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.

Sample Input

Input
2 2
1 99
100 0
Output
YES
Input
10 1
100 100
Output
NO

Hint

In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.

In the second sample Kirito's strength is too small to defeat the only dragon and win.

奥特曼要来打小怪兽啦~不过他需要把所有的小怪兽都打败才能通关。每个恐龙的属性有恐龙自己的能量,和打败恐龙后奥特曼能获得的能量,能通关就输出YES,否则输出NO。在这里奥特曼能获得的能量都是正的,所以这个题就简单啦,打败比自己能量少的的恐龙后获得能量再去打败其他恐龙。这题唯独值得收获的是sort函数的新用法用在结构体中超级爽啊!先把代码贴上紧接着再总结一下sort函数。

#include<iostream>
#include<algorithm>
using namespace std; struct D
{
int x;
int y;
};
bool cmp (D a,D b)
{
return a.x < b.x;
}
int main()
{
int s,n,i = ,j = ,k,e,f;
struct D a[],b[];
cin >> s>> n;
while(n--)
{
cin >> e>> f;
if(e < s)
{
a[i].x = e;
a[i].y = f;
i++;
}
if(e >= s)
{
b[j].x = e;
b[j].y = f;
j++;
}
}
sort(b,b+j,cmp);
for(k = ;k < i;k++)
s += a[k].y;
for(k = ;k < j;k++)
{
if(s > b[k].x)
s += b[k].y;
else
break;
}
if(k == j)cout <<"YES"<<endl;
else cout<< "NO"<<endl;
return ;
}

上面是我的代码不过大神的代码中cmp函数比我想的周全,先贴上来。

bool cmp(data a,data b)
{
if (a.x < b.x)
return true;
if (a.x == b.x && a.y > b.y)
return true;
return false;
}

sort函数在做题的时候经常能够用上,也很方便有用。sort函数共有3个参数,起始位置,终止位置,比较函数。起始和结束的区间是左闭右开的(这个我还真是今天才注意到)。比较函数是bool型的。字符串也能作为参数。默认的排序是升序的。下面给出几个个cmp函数以供参考。

bool cmp(int a,int b)
{
return a > b; //如果a > b 就返回true 这样就是按照降序排列
}
bool cmp(node x, node y) //参数类型为结构体
{
if(x.a != y.a) return x.a < y.a; //先按a的升序排;
if(x.b != y.b) return x.b > y.b; //如果a相等,就再按照b的降序排列
if(x.c != y.c) return x.c > y.c; //如果b也相等,就按照c的降序排列
}
B - T-primes

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integertТ-prime, if t has exactly three distinct positive divisors.

You are given an array of n positive integers. For each of them determine whether it is Т-prime or not.

Input

The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains nspace-separated integers xi (1 ≤ xi ≤ 1012).

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64dspecifier.

Output

Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't.

Sample Input

Input
3
4 5 6
Output
YES
NO
NO

输入一个数,检验他是不是因子有且只有3个(包括1和他本身)。想法是:检验这个数能否开根号(不能被开根号的话一定不符合要求)且开根号得到的数必须是素数。(注意判断素数的循环,容易超时)

#include<stdio.h>
#include<math.h>
int main()
{
__int64 s,m;
int prime(__int64 x);
int n;
scanf("%d",&n);
while(n--)
{
scanf("%I64d",&s);
if(s==)
{
printf("NO\n");
continue;
}
m=sqrt(s);
if((m*m)!=s)
{
printf("NO\n");
continue;
}
else
{
if(prime(m) == )
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
}
return ;
}
int prime(__int64 x)
{
int i;
for(i=;i<=sqrt(x);i++)
{
if(x%i==)
return ;
}
return ;
}

OUC_Summer Training_ DIV2_#7 718的更多相关文章

  1. OUC_Summer Training_ DIV2_#16 725

    今天做了这两道题真的好高兴啊!!我一直知道自己很渣,又贪玩不像别人那样用功,又没有别人有天赋.所以感觉在ACM也没有学到什么东西,没有多少进步.但是今天的B题告诉我,进步虽然不明显,但是只要坚持努力的 ...

  2. OUC_Summer Training_ DIV2_#13 723afternoon

    A - Shaass and Oskols Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  3. OUC_Summer Training_ DIV2_#12(DP1) 723

    这一次是做练习,主要了解了两个算法,最大子矩阵和,最长上升子序列. 先看题好啦. A - To The Max Time Limit:1000MS     Memory Limit:32768KB   ...

  4. OUC_Summer Training_ DIV2_#14 724

    又落下好多题解啊...先把今天的写上好了. A - Snow Footprints Time Limit:1000MS     Memory Limit:262144KB     64bit IO F ...

  5. OUC_Summer Training_ DIV2_#2之解题策略 715

    这是第一天的CF,是的,我拖到了现在.恩忽视掉这个细节,其实这一篇只有一道题,因为这次一共做了3道题,只对了一道就是这一道,还有一道理解了的就是第一篇博客丑数那道,还有一道因为英语实在太拙计理解错了题 ...

  6. OUC_Summer Training_ DIV2_#11 722

    企鹅很忙系列~(可惜只会做3道题T_T) A - A Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d &am ...

  7. OUC_Summer Training_ DIV2_#9 719

    其实自己只会做很简单的题,有时都不想写解题报告,觉得不值得一写,但是又想到今后也许就不会做ACM了,能留下来的东西只有解题报告了,所以要好好写,很渣的题也要写,是今后的纪念. B - B Time L ...

  8. OUC_Summer Training_ DIV2_#5

    这是做的最好的一次了一共做了4道题  嘻嘻~ A - Game Outcome Time Limit:2000MS     Memory Limit:262144KB     64bit IO For ...

  9. OUC_Summer Training_ DIV2_#4之数据结构

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26100#problem/A A - A Time Limit:1000MS     Me ...

随机推荐

  1. EasyUI中的重要的控件和属性

    data-options: precision:2     保留2为小数 validType:

  2. 服务框架 Pigeon 的设计与实现

    1.服务框架Pigeon架构 监控系统 - CAT,负责调用链路分析.异常监控告警 配置中心 - Lion,负责一些开关配置读取 服务治理 - Governor 一个interface定义为一个服务, ...

  3. Heap(堆)与Stack(栈)的区别详解

    在了解堆与栈之前,我们想来了解下程序的内存分配 一个编译的程序占用的内存分为以下几个部分  :  1.栈区(stack)—   由编译器自动分配释放   ,存放函数的参数值,局部变量的值等.其    ...

  4. Dart的List比较特殊的几个API

    List里面常用的属性和方法: 常用属性: length 长度 reversed 翻转 isEmpty 是否为空 isNotEmpty 是否不为空 常用方法: add 增加 addAll 拼接数组 i ...

  5. vi和vim的使用

    本章内容: vi编辑器简介 vim基本使用 vim使用技巧 一.vim简介 vim是一个全屏幕纯文本编辑器,是vi编辑器的增强版. 二.vim的基本使用 1.vim的工作模式 命令模式:是主要使用快键 ...

  6. Linux学习笔记(三)Linux常用命令:链接命令和文件查找命令

    一.链接命令 ln -s [原文件] [目标文件] (link) -s意为创建软连接 硬链接和软连接 硬链接的特点: (1)拥有相同的 i 结点和block块,可以看作是同一个文件 (2)可以通过 i ...

  7. Vue介绍:vue导读3

    一.全局组件 二.父组件传递信息给子组件 三.子组件传递信息给父组件 四.vue项目开发 一.全局组件 <body> <!-- 两个全局vue实例可以不用注册全局组件,就可以使用 - ...

  8. Python 爬虫实现天气查询(可视化界面版)

    github项目地址:StarMan Python 实现天气查询的程序早已完成,近日开学无课,昨晚心血来潮想做一个较为友好的界面版本,便匆忙行动了起来. 在之前已有的程序的基础上使用Tkinter 模 ...

  9. git log master..origin/master --oneline | wc -l 怎么知道本地仓库是不是最新的

    git log master..origin/master --oneline | wc -l 怎么知道本地仓库是不是最新的 git fetch   # 一定要先 fetch git log mast ...

  10. 记一次基于 mpvue 的小程序开发及上线实战

    小程序名称:一起打车吧 项目地址: 客户端:https://github.com/jrainlau/taxi-together-client 服务端:https://github.com/jrainl ...