Codeforces AIM Tech Round3
打得最烂一场Codeforces,多次都错题,无限WA。。。
A题:
题意:给定n个橘子的大小,大小超过b的丢掉,不足d的补充进来,同时超过d的部分去掉,问要去掉几次
分析:直接模拟即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=;
int a[maxn];
int n,b,d;
int main()
{
while(cin>>n>>b>>d)
{
for(int i=;i<n;i++)
scanf("%d",&a[i]);
vector<int> que;
for(int i=;i<n;i++)
{
if(a[i]<=b)
que.push_back(a[i]);
}
queue<int> q;
while(!q.empty())
q.pop();
int cnt=;
for(int i=;i<que.size();i++)
{
int t=que[i];
q.push(t);
}
while(!q.empty())
{
int h=q.front();
q.pop();
while(h<=d)
{
if(q.empty()) break;
int f=q.front();
q.pop();
h+=f;
if(h>d)
{
cnt++;
break;
}
}
}
cout<<cnt<<endl;
}
return ;
}
B题:
题意:给定n个点的坐标,同时给定一个点的坐标,求这个点到达其中n-1个点的最短路径
分析:因为必将到达a[n-1]或者a[0],所以我们先将n个点的坐标进行排序,然后比较覆盖a[n-1]和a[0]的所有情况下的最小值,注意n=1的时候结果为0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=;
int a[maxn];
int n,d;
int main()
{
while(cin>>n>>d)
{
for(int i=;i<n;i++)
scanf("%d",&a[i]);
if(n==){
cout<<""<<endl;
continue;
}
sort(a,a+n);
int h=<<;
int cnt=<<;
if(d<=a[])
{
cout<<abs(a[n-]-d)<<endl;
continue;
}else if(a[n-]<=d)
{
cout<<abs(a[]-d)<<endl;
continue;
}
if(d>=a[]&&d<=a[])
{
h=abs(a[n-]-d);
}
if(d<=a[n-]&&d>=a[n-])
{
h=min(h,abs(a[]-d));
}
cnt=min(cnt,*(abs(a[]-d))+abs(a[n-]-d));
cnt=min(cnt,*(abs(a[n-]-d))+abs(a[]-d));
cnt=min(cnt,*(abs(a[n-]-d))+abs(a[]-d));
cnt=min(cnt,*(abs(a[]-d))+abs(a[n-]-d));
cout<<min(h,cnt)<<endl;
}
return ;
}
C题:
题意:给定一个字符串,然后对于其中的一个子串进行如下变化,每个字母变成它的前一个字母,a变成z,求变化以后字典序最小
分析:开始不理解字典序,后来知道就是让排在前面的数尽量小。这样就可以贪心,对于排在尽量靠前不含有a的子串进行变化,若全是a,则将最后一个a变成z即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
string s;
int main()
{
while(cin>>s)
{
int n=s.length();
int flag=;
for(int i=;i<n;i++)
{
if(s[i]!='a')
{
flag=;
s[i]=s[i]-;
}else if(s[i]=='a'&&flag)
{
break;
}
}
if(flag)
{
for(int i=;i<n;i++)
printf("%c",s[i]);
}else{
for(int i=;i<n-;i++)
printf("%c",s[i]);
printf("z");
}
printf("\n");
}
return ;
}
Codeforces AIM Tech Round3的更多相关文章
- Codeforces AIM Tech Round (Div. 2)
这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...
- 【Codeforces AIM Tech Round 4 (Div. 2) C】
·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意: 输入一个长度为n的无重复元素的序列{a1,a2……an}(1<= ...
- codeforces AIM Tech Round 4 div 2
A:开个桶统计一下,但是不要忘记k和0比较大小 #include<bits/stdc++.h> using namespace std; ]; ]; int main() { int k; ...
- Codeforces Aim Tech Round4 (Div2) D
题目链接: 题意: 给你一个严格升序的单链表,但是是用数组来存放的.对于每一个位置来说,你可以知道这个位置的值和下一个的位置.你每一个可以询问一个位置,机器会告诉你这个位置的值,和下一个位置的指针.要 ...
- Codeforces AIM Tech Round 5 (rated, Div. 1 + Div. 2)
A. Find Square time limit per test: 1 second memory limit per test: 256 megabytes input: standard in ...
- AIM Tech Round 5 1028cf(A-E)
AIM Tech Round 5 (codeforces上题目编号是1028)(A-E) ---完全被这次比赛打击,自己真的很渣--- 战况 依旧3题选手 被构造题坑得好惨 稍稍涨了rating,希望 ...
- codeforce AIM tech Round 4 div 2 B rectangles
2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...
- AIM Tech Round 3 (Div. 2) (B C D E) (codeforces 709B 709C 709D 709E)
rating又掉下去了.好不容易蓝了.... A..没读懂题,wa了好几次,明天问队友补上... B. Checkpoints 题意:一条直线上n个点x1,x2...xn,现在在位置a,求要经过任意n ...
- 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 ...
随机推荐
- storm serializable
http://www.programgo.com/article/68283366567/
- linux 文件系统操作()
1. 用Xshell 客户端连上远程主机. 2.ll 或 ls 查看当前目录下的文件或目录, cd / 切换到根目录, cd **切换到某个目录(或者叫进入某个文件夹) 3.文件的压缩命令:zip - ...
- ssh登录nat模式的VMware虚拟机
有时候本地PC是固定IP上网方式且无多余IP,而我们又希望使用putty登陆VMware中的虚拟机且虚拟机可以上外网,那么这时候就可以使用端口映射. 1.本地环境简述 本地PC IP:192.168. ...
- 【转】ThinkPHP 页面跳转
ThinkPHP 提供了success 与error 方法用于带提示信息的页面跳转,如添加数据后显示提示信息并跳转等.success 方法用于操作成功后的提示,error 用于操作失败后的提示,二者使 ...
- php 四种基础算法 ---- 选择排序法
2. 选择排序法: 选择排序法思路: 每次选择一个相应的元素,然后将其放到指定的位置 代码: function select_sort($arr) {//实现思路 双重循环完成,外层控制轮数,当前的最 ...
- webview h5页面 关闭
说明:在 ios 安卓 客户端上的h5页面执行完毕关闭h5页面 引入的js在文件中的xhdoctor_mobile.rar
- SQL Server触发器的禁用和启用
禁用: ALTER TABLE trig_example DISABLE TRIGGER trig1 GO 恢复: ALTER TABLE trig_example ENABLE TRIGGER tr ...
- java 对象的上转型对象(父类)
Example5_10.java class 类人猿 { void crySpeak(String s) { System.out.println(s); } } class People exten ...
- POJ 1470 Closest Common Ancestors(LCA 最近公共祖先)
其实这是一个裸求LCA的题目,我使用的是离线的Tarjan算法,但是这个题的AC对于我来说却很坎坷……首先是RE,我立马想到数组开小了,然后扩大了数组,MLE了……接着把数组调整适当大小,又交了一发, ...
- CSS3中的skew()属性
刚开始接触CSS3的2D变换属性,就被这个skew()搞的一头雾水,不知道具体是怎么变化的! 研究了一会才发现,CSS3的斜切坐标系和数学中的坐标系完全不一样(设置斜切原点为左上角) <styl ...