1289 大鱼吃小鱼 1305 Pairwise Sum and Divide 1344 走格子 1347 旋转字符串 1381 硬币游戏
1289 大鱼吃小鱼
第1行:1个数N,表示鱼的数量(1 <= N <= 100000)。
第2 - N + 1行:每行两个数A[i], B[i],中间用空格分隔,分别表示鱼的大小及游动的方向(1 <= A[i] <= 10^9,B[i] = 0 或 1,0表示向左,1表示向右)。
输出1个数,表示最终剩下的鱼的数量。
5
4 0
3 1
2 0
1 0
5 0
2
输入的先后顺序即为位置,可以以左边开始,就是如果向左游就和前面的向右游的鱼判断大小,如果没有就不要管它了(随它游吧),然后吃了的话总数减少。。。就好了。
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std; const int NN=;
int n,top,ans;
int a[NN]; int main()
{
scanf("%d",&n);
top=,ans=;
int x,y;
for (int i=;i<=n;i++)
{
scanf("%d%d",&x,&y);
if (y==)
{
for (;top>;top--)
if (x>a[top]) ans++;
else
{
ans++;
break;
}
}
else a[++top]=x;
}
printf("%d\n",n-ans);
}
1305 Pairwise Sum and Divide
第1行:1个数N,表示数组A的长度(1 <= N <= 100000)。
第2 - N + 1行:每行1个数A[i](1 <= A[i] <= 10^9)。
输出fun(A)的计算结果。
3
1 4 1
4
一开始还是去模拟了,发现超时,还去删除了一些头文件,真蠢,发现分母是相乘的那么向下取整,很快就为0了,排个序,找找单调性,就解决了。
#include<cstdio>
#include<algorithm>
using namespace std; typedef long long LL;
const int NN=; int n;
int a[NN]; int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
LL sum=;
for (int i=;i<=n;i++)
for (int j=i+;j<=n;j++)
{
LL x=(LL)(a[i]+a[j])/((LL)a[i]*a[j]);
if (x==) break;
sum=sum+x;
}
printf("%lld",sum);
}
1344 走格子
第1行:1个数n,表示格子的数量。(1 <= n <= 50000)
第2 - n + 1行:每行1个数A[i],表示格子里的能量值(-1000000000 <= A[i] <= 1000000000)
输出1个数,对应从1走到n最少需要多少初始能量。
5
1
-2
-1
3
4
2
顺序下去,找一个最小负值就好了。
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std; const long long INF=1e16+; int main()
{
long long x=,y,ans=INF;
int n;
scanf("%d",&n);
for (int i=;i<=n;i++)
{
scanf("%lld",&y);
x+=y;
ans=min(ans,x);
}
if (ans<) printf("%lld\n",abs(ans));
else printf("0\n");
}
1347 旋转字符串
S[0...n-1]是一个长度为n的字符串,定义旋转函数Left(S)=S[1…n-1]+S[0].比如S=”abcd”,Left(S)=”bcda”.一个串是对串当且仅当这个串长度为偶数,前半段和后半段一样。比如”abcabc”是对串,”aabbcc”则不是。
现在问题是给定一个字符串,判断他是否可以由一个对串旋转任意次得到。
第1行:给出一个字符串(字符串非空串,只包含小写字母,长度不超过1000000)
对于每个测试用例,输出结果占一行,如果能,输出YES,否则输出NO。
aa
ab
YES
NO
一开始一位hash去搞,后来不想打代码,花了60去看了别人代码,发现了一个规律,如果是对串旋转后也是具有对串性质,所以直接比较就好了。
#include <iostream>
#include <cstring>
using namespace std;
char str[];
int main()
{
while(cin>>str)
{
int flag=;
int len=strlen(str);
if(len%!=)
{
cout<<"NO"<<endl;
continue;
}
for(int i=;i<len/;i++)
{
if(str[i]!=str[i+len/])
{
cout<<"NO"<<endl;
flag=;
break;
}
}
if(!flag)
cout<<"YES"<<endl;
}
return ;
}
1381 硬币游戏
有一个简单但是很有趣的游戏。在这个游戏中有一个硬币还有一张桌子,这张桌子上有很多平行线(如下图所示)。两条相邻平行线之间的距离是1,硬币的半径是R,然后我们来抛硬币到桌子上,抛下之后硬币有时候会和一些直线相交(相切的情况也算是相交),有时候不会。
请你来计算一下抛一次硬币之后,该硬币和直线相交数目的期望。

第一行给出一个整数T,表示有T组数据(1<=T<=10000)。
第2行到T+1,每行给出一个整数R。(0< R <= 10,000,000,000)
对于每一个数据,在一行中输出答案的整数部分即可。
1
1
2
一开始看到期望吓傻,然后发现输入都是整数,发现乘2就可以了(不理解的花哥图看看就知道了)。
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std; int n; int main()
{
scanf("%d",&n);
int x;
for (int i=;i<=n;i++)
{
scanf("%d",&x);
printf("%d\n",x*);
}
}
1289 大鱼吃小鱼 1305 Pairwise Sum and Divide 1344 走格子 1347 旋转字符串 1381 硬币游戏的更多相关文章
- 1305 Pairwise Sum and Divide
1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 有这样一段程序,fun会对 ...
- 1305 Pairwise Sum and Divide(数学 ,规律)
HackerRank 1305 Pairwise Sum and Divide 有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整: fun(A) sum = ...
- 51Nod 1305 Pairwise Sum and Divide | 思维 数学
Output 输出fun(A)的计算结果. Input示例 3 1 4 1 Output示例 4 first try: #include "bits/stdc++.h" using ...
- [51nod] 1305 Pairwise Sum and Divide 数学
有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整: fun(A) sum = 0 for i = 1 to A.length for j = ...
- 51nod 1305 Pairwise Sum and Divide
有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整: fun(A) sum = 0 for i = 1 to A.length for j = ...
- 51nod 1305:Pairwise Sum and Divide
1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 有这样一段 ...
- Pairwise Sum and Divide 51nod
1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 有这样 ...
- 51nod1305 Pairwise Sum and Divide
题目链接:51nod 1305 Pairwise Sum and Divide 看完题我想都没想就直接暴力做了,AC后突然就反应过来了... Floor( (a+b)/(a*b) )=Floor( ( ...
- 51Nod 1344 走格子(贪心
1344 走格子 有编号1-n的n个格子,机器人从1号格子顺序向后走,一直走到n号格子,并需要从n号格子走出去.机器人有一个初始能量,每个格子对应一个整数A[i],表示这个格子的能量值.如果A[i ...
随机推荐
- ctf常见php弱类型分析
1. 布尔反序列化 $unserialize_str = $_POST['password']; $data_unserialize = unserialize($unserialize_str); ...
- java HashSet改用
写的一个Student类如下: 上面是直接使用的HashSet集合,系统会把new Student() 当做地址不用来出来,所以结果如下: 然后我在Student类中重写了hashCode()和eq ...
- Day1 - 服务器硬件基础
1.1 关于运维人员 1.1.1 运维的职责 1.保证服务器7*24小时 运行 2.保证数据不能丢 3.提高用户的体验(网站打开的速度) 1.1.2 运维原则 简单.易用.高效 === 简单.粗暴 ...
- mysql 数据库安装步骤个人总结
1.mysql-5.7.19-winx64.zip(此为免安装版,318兆左右,还有一种是安装版,380兆左右mysql-installer-community-5.7.19.0.msi)将此安装包解 ...
- [js高手之路]深入浅出webpack教程系列5-插件使用之html-webpack-plugin配置(中)
上文我们讲到了options的配置和获取数据的方式,本文,我们继续深入options的配置 一.html-webpack-plugin插件中的options除了自己定义了一些基本配置外,我们是可以任意 ...
- Spring中实现文件上传
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt110 实现图片上传 用户必须能够上传图片,因此需要文件上传的功能.比较常见 ...
- CPU和GPU的差别
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt317 首先需要解释CPU和GPU这两个缩写分别代表什么.CPU即中央处理器, ...
- poj 2762 强连通缩点+拓扑排序
这题搞了好久,先是拓扑排序这里没想到,一开始自己傻乎乎的跑去找每层出度为1的点,然后才想到能用拓扑排序来弄. 拓扑排序的时候也弄了挺久的,拓扑排序用的也不多. 题意:给一个图求是否从对于任意两个点能从 ...
- ASP.NET 控制器
1.继承Controller public class TestController : Controller2.编写控制器方法 // URL : test/Edit/1 [ ...
- CCIE-MPLS VPN-实验手册(下卷)
10:跨域的MPLS VPN (Option A) 10.1 实验拓扑 10.1 实验需求 a. R1 R2 R3 组成P-NETWORK R1 R2 R3 位于AS 1,底层协议采用EI ...