AtCoder 赛 236

AtCoder 赛 236,第1张

AtCoder 赛 236

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∣≤101 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

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

#include
int main(){
	char a[100];
	scanf("%s",a);
	int n,m;
	scanf("%d%d",&n,&m);
	n--;
	m--;
	char temp=a[n];
	a[n]=a[m];
	a[m]=temp;
	printf("%s",a);
}

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

#include
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define pb push_back
#define fir first
#define sec second
#define SZ(x) ((int)x.size())
#define pii pair
templatevoid ckmin(T1&x,T2 y){if(x>y)x=y;}
templatevoid ckmax(T1&x,T2 y){if(xvoid print(T x){
    if(x<0)putchar('-'),x=-x;
    if(x>=10)print(x/10);
    putchar(x%10+'0');
}
templatevoid print(T x,char let){print(x),putchar(let);}
 
string s;int a,b;
 
int main(){
    cin>>s>>a>>b;
    a--,b--,swap(s[a],s[b]);
    cout< 
  

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.44114422ldots…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≤1051 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​=kAll 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

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

#include
int a[100001];
int main()
{
	int n;
	scanf("%d",&n);
	int k;
	for(int i=0;i<4*n-1;i++){
		scanf("%d",&k);
		a[k]++;
	}
	for(int i=1;i<=n;i++){
		if(a[i]!=4)
			printf("%d",i);
	}
}

c++

#include 
 
using namespace std;
 
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int x = 0;
  for (int i = 0; i < 4 * n - 1; i++) {
    int y;
    cin >> y;
    x ^= y;
  }
  cout << x << 'n';
  return 0;
}

使用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≤105NN and are integers.MMS_iSi​ (1 leq i leq N)(1≤iN) is a string of length between and (inclusive) consisting of lowercase English letters.111010S_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.

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

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

#include
#include
char a[100000][10];
char b[100000][10];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i 
      

c++ 打表的方法,用map将数组名命名成字符串,mapmp;

#include 
 
using namespace std;
 
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector res(n, false);
  map mp;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    mp[s] = i;
  }
  for (int j = 0; j < m; j++) {
    string s;
    cin >> s;
    res[mp[s]] = true;
  }
  for (int i = 0; i < n; i++) {
    cout << (res[i] ? "Yes" : "No") << 'n';
  }
  return 0;
}

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5713980.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存