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)的更多相关文章

  1. AIM Tech Round (Div. 1) D. Birthday 数学 暴力

    D. Birthday 题目连接: http://www.codeforces.com/contest/623/problem/D Description A MIPT student named M ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. AIM Tech Round (Div. 2) A. Save Luke 水题

    A. Save Luke 题目连接: http://codeforces.com/contest/624/problem/A Description Luke Skywalker got locked ...

  6. Codeforces AIM Tech Round (Div. 2)

    这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...

  7. 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 ...

  8. 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 ...

  9. AIM Tech Round (Div. 1) C. Electric Charges 二分

    C. Electric Charges 题目连接: http://www.codeforces.com/contest/623/problem/C Description Programmer Sas ...

  10. 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 ...

随机推荐

  1. FatMouse' Trade (贪心)

    #include <iostream> #include <stdio.h> #include <cstring> #include <cmath> # ...

  2. laravel微信自定义分享

    https://blog.csdn.net/weixin_41530218/article/details/80777036 今天接触到了微信分享,来记录一下自己所理解的一些逻辑,首先,我画了一个草图 ...

  3. LintCode_408 二进制求和

    给定两个二进制字符串,返回他们的和(用二进制表示). 思路 string s = ""; 目标字符串 cp 存储进位;取 0或1 sum = a[i] + b[i] + cp;分为 ...

  4. JFinalConfig

    概述 基于JFinal的web项目需要创建一个继承自JFinalConfig类的子类,该类用于对整个web项目进行配置. JFinalConfig子类需要实现六个抽象方法,如下所示: public c ...

  5. Deserializing/Serializing SOAP Messages in C#

    /// <summary>   /// Converts a SOAP string to an object   /// </summary>   /// <typep ...

  6. 【JZOJ4763】【NOIP2016提高A组模拟9.7】旷野大计算

    题目描述 输入 输出 样例输入 5 5 9 8 7 8 9 1 2 3 4 4 4 1 4 2 4 样例输出 9 8 8 16 16 数据范围 解法 离线莫队做法 考虑使用莫队,但由于在删数的时候难以 ...

  7. 初探postman

    第一种:安装postman 扩展程序 第二种:本地 安装postman 登陆进来postman的界面 发送第一个postman请求 将请求保存到集合 未完,待续...

  8. 装了ubuntu之后,只能进入ubuntu系统,不能进入windows系统

    电脑之前安装的是Windows 7系统, 后来在安装Linux系统中(快要完成)出现了故障, 没办法只能关机,之后重启,重启后只能进入Linux系统了 解决方案: 使用sudo update-grub ...

  9. Kernal Panic - Not syncing : VFS: unable to mount root fs on unknown-block

    升级了一下centos6.5 执行了 yum -y update reboot 出现了以下问题: Kernal Panic - Not syncing : VFS: unable to mount r ...

  10. hdu 3466 01背包变形【背包dp】

    http://acm.hdu.edu.cn/showproblem.php?pid=3466 有两个物品P,Q,V分别为 3 5 6, 5 10 5,如果先dp第一个再dp第二个,背包容量至少要为3+ ...