当前位置:   article > 正文

AtCoder 赛 236_atcoder航空路線図 (airline route map)

atcoder航空路線図 (airline route map)

A - chukodai


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : points100100

Problem Statement

You are given a string consisting of lowercase English letters.SS

Swap the -th and -th characters from the beginning of and print the resulting string.aabbSS

Constraints

  • SS is a string consisting of lowercase English letters.
  • The length of , , satisfies .SS|S|∣S∣2 \leq |S| \leq 102≤∣S∣≤10
  • 1 \leq a < b \leq |S|1≤a<b≤∣S
  • aa and are integers.bb

Input

Input is given from Standard Input in the following format:

SS
aa bb

Output

Print the answer.


Sample Input 1

chokudai
3 5

Sample Output 1

chukodai

After swapping the -rd character and -th character of , we have .33o55uchokudaichukodai


Sample Input 2

aa
1 2

Sample Output 2

aa

In this sample, after swapping the -st and -nd characters of , we have the same string as .1122SSSS


Sample Input 3

aaaabbbb
1 8

Sample Output 3

baaabbba

思路:直接来,数组元素交换

  1. #include<stdio.h>
  2. int main(){
  3. char a[100];
  4. scanf("%s",a);
  5. int n,m;
  6. scanf("%d%d",&n,&m);
  7. n--;
  8. m--;
  9. char temp=a[n];
  10. a[n]=a[m];
  11. a[m]=temp;
  12. printf("%s",a);
  13. }

可以用c++里的sawp,某大佬的源码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define rep(i,l,r) for(int i=(l);i<=(r);i++)
  6. #define per(i,l,r) for(int i=(l);i>=(r);i--)
  7. #define pb push_back
  8. #define fir first
  9. #define sec second
  10. #define SZ(x) ((int)x.size())
  11. #define pii pair<int,int>
  12. template<class T1,class T2>void ckmin(T1&x,T2 y){if(x>y)x=y;}
  13. template<class T1,class T2>void ckmax(T1&x,T2 y){if(x<y)x=y;}
  14. inline int read(){
  15. int x=0,f=0;char ch=getchar();
  16. while(!isdigit(ch))f|=ch=='-',ch=getchar();
  17. while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
  18. return f?-x:x;
  19. }
  20. template<class T>void print(T x){
  21. if(x<0)putchar('-'),x=-x;
  22. if(x>=10)print(x/10);
  23. putchar(x%10+'0');
  24. }
  25. template<class T>void print(T x,char let){print(x),putchar(let);}
  26. string s;int a,b;
  27. int main(){
  28. cin>>s>>a>>b;
  29. a--,b--,swap(s[a],s[b]);
  30. cout<<s;
  31. }

B - Who is missing?


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : points200200

Problem Statement

We have cards with an integer written on it, cards with , , cards with , for a total of cards.44114422\ldots…44NN4N4N

Takahashi shuffled these cards, removed one of them, and gave you a pile of the remaining cards. The -th card of the pile has an integer written on it.4N-14N−1ii(1 \leq i \leq 4N - 1)(1≤i≤4N−1)A_iAi

Find the integer written on the card removed by Takahashi.

Constraints

  • 1 \leq N \leq 10^51≤N≤105
  • 1 \leq A_i \leq N \, (1 \leq i \leq 4N - 1)1≤Ai​≤N(1≤i≤4N−1)
  • For each , there are at most indices such that .k \, (1 \leq k \leq N)k(1≤kN)44iiA_i = kAi​=k
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN
A_1A1​ A_2A2​ \ldots… A_{4N - 1}A4N−1​

Output

Print the answer.


Sample Input 1

3
1 3 2 3 3 2 2 1 1 1 2

Sample Output 1

3

Takahashi removed a card with written on it.33


Sample Input 2

1
1 1 1

Sample Output 2

1

Sample Input 3

4
3 2 1 1 2 4 4 4 4 3 1 3 2 1 3

Sample Output 3

2

思路:每种数有四个,直接用一个一个的桶装起来

  1. #include<stdio.h>
  2. int a[100001];
  3. int main()
  4. {
  5. int n;
  6. scanf("%d",&n);
  7. int k;
  8. for(int i=0;i<4*n-1;i++){
  9. scanf("%d",&k);
  10. a[k]++;
  11. }
  12. for(int i=1;i<=n;i++){
  13. if(a[i]!=4)
  14. printf("%d",i);
  15. }
  16. }

c++

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #ifdef LOCAL
  4. #include "algo/debug.h"
  5. #else
  6. #define debug(...) 42
  7. #endif
  8. int main() {
  9. ios::sync_with_stdio(false);
  10. cin.tie(0);
  11. int n;
  12. cin >> n;
  13. int x = 0;
  14. for (int i = 0; i < 4 * n - 1; i++) {
  15. int y;
  16. cin >> y;
  17. x ^= y;
  18. }
  19. cout << x << '\n';
  20. return 0;
  21. }

使用x^=y,当y输入是两个相同的元素时,则x=0,所以可以统计出少的那个数(因为只会少一个数)

C - Route Map


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : points300300

Problem Statement

There are stations on a certain line operated by AtCoder Railway. The -th station from the starting station is named .NNii(1 \leq i \leq N)(1≤iN)S_iSi

Local trains stop at all stations, while express trains may not. Specifically, express trains stop at only stations, and the -th stop is the station named .
Here, it is guaranteed that and , that is, express trains stop at both starting and terminal stations.M \, (M \leq N)M(MN)jj(1 \leq j \leq M)(1≤jM)T_jTj​T_1 = S_1T1​=S1​T_M = S_NTM​=SN

For each of the stations, determine whether express trains stop at that station.NN

Constrains

  • 2 \leq M \leq N \leq 10^52≤MN≤105
  • NN and are integers.MM
  • S_iSi​ (1 \leq i \leq N)(1≤iN) is a string of length between and (inclusive) consisting of lowercase English letters.111010
  • S_i \neq S_j \, (i \neq j)Si​=Sj​(i=j)
  • T_1 = S_1T1​=S1​ and .T_M = S_NTM​=SN
  • (T_1, \dots, T_M)(T1​,…,TM​) is obtained by removing zero or more strings from and lining up the remaining strings without changing the order.(S_1, \dots, S_N)(S1​,…,SN​)

Input

Input is given from Standard Input in the following format:

NN MM
S_1S1​ \ldots… S_NSN​
T_1T1​ \ldots… T_MTM

Output

Print lines. The -th line should contain if express trains stop at the -th station from the starting station, and otherwise.NNii(1 \leq i \leq N)(1≤iN)YesiiNo


Sample Input 1

5 3
tokyo kanda akiba okachi ueno
tokyo akiba ueno

Sample Output 1

Yes
No
Yes
No
Yes

Sample Input 2

7 7
a t c o d e r
a t c o d e r

Sample Output 2

Yes
Yes
Yes
Yes
Yes
Yes
Yes

Express trains may stop at all stations.

(时间超限一次).......

思路:火车是一直向前的所以出现过一次就不会再出现了

  1. #include<stdio.h>
  2. #include<string.h>
  3. char a[100000][10];
  4. char b[100000][10];
  5. int main()
  6. {
  7. int n,m;
  8. scanf("%d%d",&n,&m);
  9. for(int i=0;i<n;i++)
  10. scanf("%s",a[i]);
  11. for(int i=0;i<m;i++)
  12. scanf("%s",b[i]);
  13. int i=0,j=0;
  14. while(j<m)
  15. {
  16. if(strcmp(a[i],b[j])==0){
  17. printf("Yes\n");
  18. j++;
  19. }
  20. else
  21. printf("No\n");
  22. i++;
  23. }
  24. return 0;
  25. }

c++ 打表的方法,用map将数组名命名成字符串,map<string,int>mp;

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #ifdef LOCAL
  4. #include "algo/debug.h"
  5. #else
  6. #define debug(...) 42
  7. #endif
  8. int main() {
  9. ios::sync_with_stdio(false);
  10. cin.tie(0);
  11. int n, m;
  12. cin >> n >> m;
  13. vector<bool> res(n, false);
  14. map<string, int> mp;
  15. for (int i = 0; i < n; i++) {
  16. string s;
  17. cin >> s;
  18. mp[s] = i;
  19. }
  20. for (int j = 0; j < m; j++) {
  21. string s;
  22. cin >> s;
  23. res[mp[s]] = true;
  24. }
  25. for (int i = 0; i < n; i++) {
  26. cout << (res[i] ? "Yes" : "No") << '\n';
  27. }
  28. return 0;
  29. }

向量(Vector)是一个封装了动态大小数组的顺序容器(Sequence Container)。跟任意其它类型容器一样,它能够存放各种类型的对象。可以简单的认为,向量是一个能够存放任意类型的动态数组

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号