Download
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 851 Accepted Submission(s): 425
Problem Description
Computer networks, the widespread sharing of information among groups of computers and their users, are a central part of the information age. In this age, every local personal computer(PC) can download applications and documents from the distance database, which makes it convenient to our entertainment by using the internet.
CC is a such fanatical lover of TV plays. Each TV play is consisted by a lot number of sections. When he open his download software and select one of his favourite TV plays, a "section selected window" jumped out. "Please mark the sections you want to download~".
Each section has its CheckBox to be marked stands for choosing this section or not.
There are two special buttons as follow:
1, All-clicked: you can mark all of section with '√' by click this button.
2, Inverse-clicked: you can change each section to its inverse state by click this button.
At first, the state of each section is in disorder, and there is no need to CC to download all of the sections in this TV play. When he are about to begin his crazy clicking, he come up with a good idea that finding the minimum times of click by programming. Now he tell you the information of the original download window, can you tell him how many click times at least to choose the sections he wants to download.
CC is a such fanatical lover of TV plays. Each TV play is consisted by a lot number of sections. When he open his download software and select one of his favourite TV plays, a "section selected window" jumped out. "Please mark the sections you want to download~".
![](https://i-blog.csdnimg.cn/blog_migrate/2c6ef8fc1ab0e381ccbc4495d2695fe7.jpeg)
Each section has its CheckBox to be marked stands for choosing this section or not.
There are two special buttons as follow:
1, All-clicked: you can mark all of section with '√' by click this button.
2, Inverse-clicked: you can change each section to its inverse state by click this button.
At first, the state of each section is in disorder, and there is no need to CC to download all of the sections in this TV play. When he are about to begin his crazy clicking, he come up with a good idea that finding the minimum times of click by programming. Now he tell you the information of the original download window, can you tell him how many click times at least to choose the sections he wants to download.
Input
Input contains multiple test cases. Each test case contains three lines:
The first line contains only one number N (5 <= N <= 50) indicating the total number of sections.
The second line is a string S only consisted by '0' and '1', the ith charactor is stand for the ith section of TV play, '1' is stand for the '√' state and '0' is not.
The third line is a string T, just like S, it shows the sections CC wants to download.
You can assume the length of S and T are equal to N.
The first line contains only one number N (5 <= N <= 50) indicating the total number of sections.
The second line is a string S only consisted by '0' and '1', the ith charactor is stand for the ith section of TV play, '1' is stand for the '√' state and '0' is not.
The third line is a string T, just like S, it shows the sections CC wants to download.
You can assume the length of S and T are equal to N.
Output
For each case, you are required to output the minimum count of clicks to choose the expected section(s).
Sample Input
5 00010 10111 5 10101 01010
Sample Output
2 1
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
int n;
char s1[100]; /*用于存储第一串字符*/
char s2[100]; /*用于存储第二串字符*/
int num[4];
while (scanf("%d", &n) != EOF)
{
getchar();
gets(s1);
gets(s2);
num[0] = 0;
for (int i = 0; i < n; i++) { /*不采取特殊操作需要的操作数*/
if (s1[i] != s2[i])
num[0]++;
}
num[1] = 1;
for (int i = 0; i < n; i++) { /*将所有的字符置1之后需要的操作数*/
if (s2[i] != '1')
num[1]++;
}
num[2] = 1;
for (int i = 0; i < n; i++) { /*将所有的字符取反之后所需要的操作数*/
if (s1[i] == s2[i])
num[2]++;
}
num[3] = 2;
for (int i = 0; i < n; i++) { /*将所有的字符置0之后所需要的操作数*/
if (s2[i] == '1')
num[3]++;
}
int min = num[0];
for (int i = 1; i < 4; i++) {
if (min > num[i])
min = num[i];
}
printf("%d\n", min);
}
return 0;
}
这个题目仔细想想还是挺有意思的,总的其实就只有四种方式去使得串1变成串2,这题的关键在于将整段字符取反(0到1,1到0)之后再逐个取反这些操作不同顺序的操作是不会改变的最终的结果的,而且两次取反之后对字符串操作就是无用操作,而把字符串全部置1以及将字符串全部置0则是另两种操作方法,因此只要把这四个操作获得的操作数取最小的就可以了