zoukankan      html  css  js  c++  java
  • 蓝桥杯 PREV-6 翻硬币

    题目链接:

    PREV-6 翻硬币

    思路:

    题目似乎并没有提到第一种状态不能转化到第二种状态的情况啊…实际上两种状态不相同的位置总数如果是奇数的话就没办法相互转化…题目也没说给定的两种状态一定可以相互转化,那我们就默认可以好了…
    我们记录所有正反不相同的硬币在字符串中出现的位置,然后贪心地去计数即可;

    代码:

    #include<bits/stdc++.h>
    
    using namespace std;
    
    int main() {
    #ifdef MyTest
    	freopen("Sakura.txt", "r", stdin);
    #endif
    	string a, b;
    	cin >> a >> b;
    	vector<int> v;
    	for(int i = 0; i < a.length(); i++) 
    		if(a[i] != b[i]) v.push_back(i);
    	int ans = 0;
    	for(int i = 1; i < v.size(); i += 2)
    		ans += v[i] - v[i - 1];
    	cout << ans;
    	return 0;	
    }
    
  • 相关阅读:
    算法
    ximalaya-spider
    无名小站
    python send email
    spider-bilibili
    windows镜像
    python 爬取豆瓣电影写入到excel中
    pdf 转 word
    文档分割、合并
    文档合并
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308608.html
Copyright © 2011-2022 走看看