Codeforces Round #396(Div. 2) A. Mahmoud and Longest Uncommon Subsequence

【题意概述】

  找两个字符串的最长不公共子串。

【题目分析】

  两个字符串的最长不公共子串就应该是其中一个字符串本身,那么判断两个字符串是否相等,如果相等,那么肯定没有公共子串,输出“-1”.否则就是两个字符串中长的最长的长度。

【AC】

1 #include<bits/stdc++.h>
2 using namespace std;
3 int main() {
4     char str1[100005],str2[100005];
5     scanf("%s%s",str1,str2);
6     if(strcmp(str1,str2) == 0 ) printf("-1\n");
7     else printf("%d\n",max(strlen(str1),strlen(str2)));
8     return 0;
9 } 

原文地址:https://www.cnblogs.com/jj81/p/8848626.html

时间: 2024-10-13 08:31:06

Codeforces Round #396(Div. 2) A. Mahmoud and Longest Uncommon Subsequence的相关文章

Codeforces Round #396 (Div. 2)C. Mahmoud and a Message(dp)

题目链接:http://codeforces.com/problemset/problem/766/C 题意:给你一组小写字母组成的字符串,和26个数字,分别对应26位小写字母能够存在的字符串的最大长度. 要求:①:求出最多的划分方案 ②:求出分配方案中,最长的子串长度 ③:求出分配方案中,最少分成的子串数 思路:关于①:设置dp[i],dp[i]表示在第i个字符后面有一个横杠的方案数,从第i个往前枚举前一个横杠的位置j. 举个例子,有子串abc,当横杠断在a处,有一种方案,dp[1]=1:当横

Codeforces Round #396 (Div. 2) D题Mahmoud and a Dictionary(并查集)解题报告

Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discov

Codeforces Round #396 (Div. 2) C题Mahmoud and a Message(dp)解题报告

Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because th

Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string[二分]

题目:http://codeforces.com/problemset/problem/862/D 题意:交互题,询问15次以内Hamming distance,输出一个二进制串里任意一个0或1的位置 题解:极简单的二分,从最后一位先判断一个,然后二分 根据上次和本次的距离差是否等于二分长度判断在左端还是右端有需要寻找的值寻找另一个. 1 #define _CRT_SECURE_NO_DEPRECATE 2 #pragma comment(linker, "/STACK:102400000,10

Codeforces Round #396 (Div. 2)

AB都是大水题. C题,题意稍微有点晦涩.但是还是一个比较简单的dp(虽然我不是独立的做出来的= =).感觉我dp掌握的不是很好啊:看到这题突然想起前几天碰到的一题:不考虑顺序的整数划分问题.C题代码如下: 1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 #include <iostream> 5 #include <string> 6 using names

Codeforces Round #435 (Div. 2) E. Mahmoud and Ehab and the function(预处理+二分)

题目链接:点我点我 题意:公式:,给出n个数,从a[1]到a[n],和m个数(b数组),然后从b数组里挑出连续的n个数(也就m-n+1中选择),按公式计算,使得f最小, 还有q次对a数组的操作(某个区间增加值,减少值),求出最小值. 题解:显然对a数组的处理非常简单,一开始确定一定值,然后update的时候,判断一下奇偶性质就可以直接加了(前一项正后一项一定是负的,可以抵消). 然后就是b数组的处理了,一开始没处理好,一直在这边卡超时.先把b数组一项一项正负不同的加进去,然后再进行处理,得到c数

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #619 (Div. 2) Ayoub&#39;s function

Ayoub thinks that he is a very smart person, so he created a function f(s)f(s) , where ss is a binary string (a string which contains only symbols "0" and "1"). The function f(s)f(s) is equal to the number of substrings in the string s

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i