Codeforces 56D Changing a String (DP) 题意:你可以对字符串s进行3种操作: 1,在pos位置插入字符ch。 2,删除pos位置的字符。 3,替换pos位置的字符为ch。 问最少需要多少次操作可以把字符s变成字符s1? 思路: 设dp[i][j]为字符串s的前i个字符替换成s1的前j个字符的最小花费。则有三种转移: 1:dp[i ...
}else{ dfs(n-1,m-1);if(a[n]!=b[m]) printf("REPLACE %d %c\n",m,b[m]); } }intmain(){ scanf("%s",a+1);n=strlen(a+1); scanf("%s",b+1);m=strlen(b+1);for(inti=0;i<=n;i++)for(intj=0;j<=m;j++) f[i][j]=0; f[0][0]=0;for(inti=1;i<=n;i++) ...
DELETEpos— delete a character numberpos(1 ≤ pos ≤ |s|) from the strings. At that the letters shift together and the length of the string decreases by 1. REPLACEposch— the letter in the positionposof the linesis replaced bych(1 ≤ pos ≤ |s|, A ≤ ch...
黑进了Codeforces,因此他可以任意修改每个用户的用户名,修改了很多次后,他想知道每个用户最原始的用户名和现在的用户名。 题解: map的运用,暴力 代码: #include<cstdio> #include<cstring> #include<map> #include<algorithm> #include<iostream> using namespace std; int main(){ string s1,s2; int n; ...
每行包括两个string。设第一个为用户的oldName,第二个为用户的newName,用newName 替换旧的oldName,可进行重复替换。最后输出用户的第一个Name 和最新的Name。举例:Input: “` 5 Misha ILoveCodeforces Vasya Petrov Petrov VasyaPetrov123 ILoveCodeforces MikeMirzayanov Petya Ivanov...
importjava.util.HashMap;importjava.util.Scanner;publicclassB501{publicstaticvoidmain(String[]args){Scanner sc=newScanner(System.in);int t=sc.nextInt();HashMap<String,String>map=newHashMap<>();while(t-->0){String a=sc.next();String b=sc.next();if(map.containsKey(a)){map.put(b,map...
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. ...
string s1, s2; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 0; i < n; i++){ cin >> s1 >> s2; if(i == 0) mp[s1] = s2; else{ int flag = 0; for(map <string, string> :: iterator it = mp.begin(); it != mp.end(); it...
Linux from scratch Machine Learning Deep Learning CodeForces OpenCV TensonFlow Keras Spring CodinGame, Halit AI projects Kaggle and DevPost ML projects Learn GDB, Valgrind Cool Stuffs int a[100] = {0}; // shorter way to initialize in cpp. yeah, I didn't know that next_permutation(v.beg...
Codeforces 56D Changing a String 2016-07-13 18:39 −... GFY 0 218 @codeforces - 715E@ Complete the Permutations 2019-12-11 09:54 −[toc] --- ## @description@ 给定两个排列 p, q,他们中的有些位置被替换成了 0。 两个排列 p, q 的距离为:最少需要在 p 中执行交换两个元素的操作...