Codeforces AIM Tech Round3

打得最烂一场Codeforces,多次都错题,无限WA。。。

A题:

题意:给定n个橘子的大小,大小超过b的丢掉,不足d的补充进来,同时超过d的部分去掉,问要去掉几次

分析:直接模拟即可

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <set>
 8 #include <map>
 9 #include <bitset>
10 #include <cmath>
11 #include <queue>
12 #include <stack>
13 using namespace std;
14 const int maxn=100020;
15 int a[maxn];
16 int n,b,d;
17 int main()
18 {
19     while(cin>>n>>b>>d)
20     {
21         for(int i=0;i<n;i++)
22             scanf("%d",&a[i]);
23         vector<int> que;
24         for(int i=0;i<n;i++)
25         {
26             if(a[i]<=b)
27                 que.push_back(a[i]);
28         }
29         queue<int> q;
30         while(!q.empty())
31             q.pop();
32         int cnt=0;
33         for(int i=0;i<que.size();i++)
34         {
35             int t=que[i];
36             q.push(t);
37         }
38         while(!q.empty())
39         {
40             int h=q.front();
41             q.pop();
42             while(h<=d)
43             {
44                 if(q.empty()) break;
45                 int f=q.front();
46                 q.pop();
47                 h+=f;
48                 if(h>d)
49                 {
50                     cnt++;
51                     break;
52                 }
53             }
54         }
55         cout<<cnt<<endl;
56     }
57     return 0;
58 }

B题:

题意:给定n个点的坐标,同时给定一个点的坐标,求这个点到达其中n-1个点的最短路径

分析:因为必将到达a[n-1]或者a[0],所以我们先将n个点的坐标进行排序,然后比较覆盖a[n-1]和a[0]的所有情况下的最小值,注意n=1的时候结果为0

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <set>
 8 #include <map>
 9 #include <bitset>
10 #include <cmath>
11 #include <queue>
12 #include <stack>
13 using namespace std;
14 const int maxn=100010;
15 int a[maxn];
16 int n,d;
17 int main()
18 {
19     while(cin>>n>>d)
20     {
21         for(int i=0;i<n;i++)
22             scanf("%d",&a[i]);
23         if(n==1){
24             cout<<"0"<<endl;
25             continue;
26         }
27         sort(a,a+n);
28         int h=1<<30;
29         int cnt=1<<30;
30         if(d<=a[0])
31         {
32             cout<<abs(a[n-2]-d)<<endl;
33             continue;
34         }else if(a[n-1]<=d)
35         {
36             cout<<abs(a[1]-d)<<endl;
37             continue;
38         }
39         if(d>=a[0]&&d<=a[1])
40         {
41             h=abs(a[n-1]-d);
42         }
43         if(d<=a[n-1]&&d>=a[n-2])
44         {
45             h=min(h,abs(a[0]-d));
46         }
47         cnt=min(cnt,2*(abs(a[0]-d))+abs(a[n-2]-d));
48         cnt=min(cnt,2*(abs(a[n-2]-d))+abs(a[0]-d));
49         cnt=min(cnt,2*(abs(a[n-1]-d))+abs(a[1]-d));
50         cnt=min(cnt,2*(abs(a[1]-d))+abs(a[n-1]-d));
51         cout<<min(h,cnt)<<endl;
52     }
53     return 0;
54 }

C题:

题意:给定一个字符串,然后对于其中的一个子串进行如下变化,每个字母变成它的前一个字母,a变成z,求变化以后字典序最小

分析:开始不理解字典序,后来知道就是让排在前面的数尽量小。这样就可以贪心,对于排在尽量靠前不含有a的子串进行变化,若全是a,则将最后一个a变成z即可。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <set>
 8 #include <map>
 9 #include <bitset>
10 #include <cmath>
11 #include <queue>
12 #include <stack>
13 using namespace std;
14 string s;
15 int main()
16 {
17     while(cin>>s)
18     {
19         int n=s.length();
20         int flag=0;
21         for(int i=0;i<n;i++)
22         {
23             if(s[i]!=‘a‘)
24             {
25                 flag=1;
26                 s[i]=s[i]-1;
27             }else if(s[i]==‘a‘&&flag)
28             {
29                 break;
30             }
31         }
32         if(flag)
33         {
34             for(int i=0;i<n;i++)
35                 printf("%c",s[i]);
36         }else{
37             for(int i=0;i<n-1;i++)
38                 printf("%c",s[i]);
39             printf("z");
40         }
41         printf("\n");
42     }
43     return 0;
44 }

时间: 2024-12-06 10:42:50

Codeforces AIM Tech Round3的相关文章

Codeforces Aim Tech Round4 (Div2) D

题目链接: 题意: 给你一个严格升序的单链表,但是是用数组来存放的.对于每一个位置来说,你可以知道这个位置的值和下一个的位置.你每一个可以询问一个位置,机器会告诉你这个位置的值,和下一个位置的指针.要你确认大于等于x的值.(询问次数不能超过2000). 题解: 由于给你的可能有5e4个数,除了随机算法,没有一种可以在2000步以内找到小于等于x. 对与随机算法:我们先随机找500个点,找到小于x的点0值中最大的一个.然后暴力询问.小于2000的直接暴力找了. 证明: 我们假设x的位置在Y, 那么

AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)

A. Diversity time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters,

AIM Tech Round 3 (Div. 2) B

Description Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x1, x2, ..., xn. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finis

AIM Tech Round 3 (Div. 2) E. Centroids

题解: 树形dp 非常好的一道题目 题意: 对于每个点.更改一条边,能否使得这个点成为树的重心 题解: 所谓重心:指去掉这个点后,最大的连通分量的点数<=n/2 对于每个点,分为向下分析,向上分析 向下分析:找寻点u的子节点的最大节点v.然后找寻节点v的子节点的小于等于n/2的最大子节点,连接到u上 向上分析:找寻点u的父节点的最大节点v.如果v==u那么.找寻次大节点w.然后找寻该点的子节点的小于等于n/2的最大子节点,连接到u上 向下分析和向上分析只需要判断一个,因为大于n/2的点只有一个

AIM Tech Round 4 (Div. 2)

A题 分析:暴力 1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "string" 5 using namespace std; 6 const int maxn=100+10; 7 int vis[maxn],n; 8 string s; 9 int main() 10 { 11 cin>>s; 12 cin>

AIM Tech Round 3 (Div. 2)

5/5 这一场是比较水的一场(当然我是指div2),所以前面三题就略过吧... 题D D. Recover the String 题意:让你构造一个01串,给你00,01,10,11的子序列个数,问你有没有满足的串. 题解:这题实际上并不难, 只是分类讨论有点麻烦. 首先是00和11一定是满足n * (n - 1)  / 2,先判定一下 然后得到0的个数x,1的个数y 然后我们注意到,现一开始所有的0放在一起,然后插入一个位置k,那么我们发现01多了k,10多了x – k:假设这y个1 的位置是

AIM Tech Round (Div. 2)

A. Save Luke 题意:给一个人的长度d,然后给一个区间长度0~L,给你两个子弹的速度v1,v2,两颗子弹从0和L向中间射去(其实不是子弹,是一种电影里面那种绞牙机之类的东西就是一个人被困在里面了,两边有着那种尖刺的墙向中间靠拢的那种)问Luke能存活的最长时间 思路:看代码吧,简单易懂 1 #include<cstdio> 2 #include<cmath> 3 int main() 4 { 5 int d,l,v1,v2; 6 while(scanf("%d%

AIM Tech Round 4 (Div. 2) A B C

A. Diversity 题意:给出一个字符串,和n,问最多改变多少个字符,使其不同字符最少为n 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=1e5+10; 5 6 map<char ,int >ma; 7 int main(){ 8 string s; 9 cin>>s; 10 int n; 11 cin>>n; 12 int

AIM Tech R3 div2 E Centroid

思路很明显了,假设是点x,则看它的子树中是否有大于n/2的,如果有,则在该子树中剪去它可以剪的且小于n/2的,接到点x上. 则统计出在以x点为根的子树中,它的各子树可以剪去的且小于n/2的最大子子树.对于除去以x为根的子树的其他部分,记为up,则同样地统计它的可以剪除的符合条件的子树,最后对每个点判断一下就可以了. 代码如下::(额,想的时候对up的这个不知道怎么写~谢指导) #include <iostream> #include <cstdio> #include <cs