AIM Tech Round (Div. 2)
A. Save Luke
题意:给一个人的长度d,然后给一个区间长度0~L,给你两个子弹的速度v1,v2,两颗子弹从0和L向中间射去(其实不是子弹,是一种电影里面那种绞牙机之类的东西就是一个人被困在里面了,两边有着那种尖刺的墙向中间靠拢的那种)问Luke能存活的最长时间
思路:看代码吧,简单易懂
#include<cstdio>
#include<cmath>
int main()
{
int d,l,v1,v2;
while(scanf("%d%d%d%d",&d,&l,&v1,&v2)!=EOF)
{
printf("%.6lf\n",(l-d)*1.0/(v1+v2));
}
}
B. Making a String
题意:26个字母组成的串,给你字母的数量和每个字母可以放的数量,组成串的时候有一定规则:
1.串中每个字母的数量不能多于给定的数量
2.串中每个字母出现的次数都不同
问组成的最长串是多少。
思路:因为涉及的是不同的元素,所以用set来做,
先贴一个WA在第20组数据的代码
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
long long num[],sum[];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
set<long long>p;
long long tot=;
for(int i=;i<n;++i)
scanf("%lld",&num[i]);
sort(num,num+n);
for(int i=n-;i>=;--i){
while(p.find(num[i])!=p.end()){
num[i]-=;
}
p.insert(num[i]);
tot+=num[i];
}
printf("%lld\n",tot);
}
}
这个代码呢,在while循环中num[i]可能减为负数,所以输入3 1 1 1 答案本来是1的但输出来是0
所以要对负数做一个判断
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
long long num[],sum[];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
set<long long>p;
long long tot=;
for(int i=;i<n;++i)
scanf("%lld",&num[i]);
sort(num,num+n);
for(int i=n-;i>=;--i){
while((p.find(num[i])!=p.end())){
num[i]-=;
}
if(num[i]<) num[i]=;
p.insert(num[i]);
tot+=num[i];
}
printf("%lld\n",tot);
}
}
这样就可以了
错误代码贴这里是为了提醒自己针对一个问题针对自己的代码要做到没有漏洞可以找、
AIM Tech Round (Div. 2)的更多相关文章
- AIM Tech Round (Div. 1) D. Birthday 数学 暴力
D. Birthday 题目连接: http://www.codeforces.com/contest/623/problem/D Description A MIPT student named M ...
- AIM Tech Round (Div. 2) D. Array GCD dp
D. Array GCD 题目连接: http://codeforces.com/contest/624/problem/D Description You are given array ai of ...
- AIM Tech Round (Div. 2) C. Graph and String 二分图染色
C. Graph and String 题目连接: http://codeforces.com/contest/624/problem/C Description One day student Va ...
- AIM Tech Round (Div. 2) B. Making a String 贪心
B. Making a String 题目连接: http://codeforces.com/contest/624/problem/B Description You are given an al ...
- AIM Tech Round (Div. 2) A. Save Luke 水题
A. Save Luke 题目连接: http://codeforces.com/contest/624/problem/A Description Luke Skywalker got locked ...
- Codeforces AIM Tech Round (Div. 2)
这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...
- AIM Tech Round (Div. 2) B
B. Making a String time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- AIM Tech Round (Div. 2) A
A. Save Luke time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- AIM Tech Round (Div. 1) C. Electric Charges 二分
C. Electric Charges 题目连接: http://www.codeforces.com/contest/623/problem/C Description Programmer Sas ...
- AIM Tech Round (Div. 2) C. Graph and String
C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- arcgis信息窗口
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 【JZOJ3216】【SDOI2013】淘金
╰( ̄▽ ̄)╭ 小 Z在玩一个 叫做<淘金者>的游戏.游戏的世界是一个 二维坐标 .X轴.Y轴坐标范围均为1..N.初始的时候,所有的整数坐标点上均有一块金子,共 N*N 块. 一阵风吹过 ...
- python进程间通信 queue pipe
python进程间通信 1 python提供了多种进程通信的方式,主要Queue和Pipe这两种方式,Queue用于多个进程间实现通信,Pipe是两个进程的通信 1.1 Queue有两个方法: Put ...
- win10下安装mongodb(解压版)
首先到官网下载安装包.(https://www.mongodb.com/download-center#community) 1.创建mongodb目录 2.配置文件mongodb.config 3. ...
- HTTP请求响应头信息
HTTP请求响应头信息 请求:(request) 组成部分: 请求行 请求头 请求体 请求行:请求信息的第一行 格式:请求方式 访问的资源 协议/版本 例如:GET /day0801/1.html H ...
- 移动web的基础知识
一.像素 px:CSS pixels逻辑像素,浏览器使用的抽象单位 dp,pt:设备无关像素 (物理像素) dpr:设备像素缩放比 计算公式: 1px = (dpr)*(dpr)*dp 二.viewp ...
- 如何把VS Code的Language Server Protocol整合到Eclipse中来
Eclipse官方已经在着手做这件事情了,在Oxygen中,Eclipse提供了LSP4E扩展点(language server protocal for eclipse)来支持language se ...
- @codeforces - 718E@ Matvey's Birthday
目录 @description@ @solution@ @accepted code@ @detail@ @description@ 给定一个长度为 n 的字符串 s,保证只包含前 8 个小写字母 ' ...
- 18.libgdx制作预览图,背景移动循环,改变地图颜色
经过构思,游戏将分为两部分, 1,预览图,只负责展示世界形势 2,根据预览图生成的战役项 现在要记录的是我制作预览图的部分 1.预览图只有实际地图的1/4,首先生成地图(建议不要缩放以前地图,由于误差 ...
- 括号序列问题 uva 1626 poj 1141【区间dp】
首先考虑下面的问题:Code[VS] 3657 我们用以下规则定义一个合法的括号序列: (1)空序列是合法的 (2)假如S是一个合法的序列,则 (S) 和[S]都是合法的 (3)假如A 和 B 都是合 ...