GVKun编程网logo

Codeforces Round #435 (Div. 2)C. Mahmoud and Ehab and the xor(异或的性质)(异或结果)

9

对于想了解CodeforcesRound#435(Div.2)C.MahmoudandEhabandthexor(异或的性质)的读者,本文将提供新的信息,我们将详细介绍异或结果,并且为您提供关于B类-

对于想了解Codeforces Round #435 (Div. 2)C. Mahmoud and Ehab and the xor(异或的性质)的读者,本文将提供新的信息,我们将详细介绍异或结果,并且为您提供关于B类-Codeforces Round #535 (Div. 3)C. Nice Garland、CF 959 E. Mahmoud and Ehab and the xor-MST、CF959E Mahmoud and Ehab and the xor-MST 思维、Codeforces #396 (Div. 2) D. Mahmoud and a Dictionary (并查集+map的有价值信息。

本文目录一览:

Codeforces Round #435 (Div. 2)C. Mahmoud and Ehab and the xor(异或的性质)(异或结果)

Codeforces Round #435 (Div. 2)C. Mahmoud and Ehab and the xor(异或的性质)(异或结果)

总结

以上是小编为你收集整理的Codeforces Round #435 (Div. 2)C. Mahmoud and Ehab and the xor(异或的性质)全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

B类-Codeforces Round #535 (Div. 3)C. Nice Garland

B类-Codeforces Round #535 (Div. 3)C. Nice Garland

Codeforces Round #535 (Div. 3)C. Nice Garland

题意:

R‘,‘G‘ and ‘B‘ 三个字母组成的一个字符串,每两个相同的字母需要相差3,找出最小需要交换次数。

分析:

这个字符串的长度大于等于3的时候,一定是RBG这三个字符的某一个排列的循环。
RBG一共最多有6种排列方式{"RGB","RBG","BGR","BRG","GRB","GBR"};

所以直接暴力循环6次即可。

代码:

#include<iostream>
using namespace std;
string dir[6]={"RGB","RBG","BGR","BRG","GRB","GBR"};
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int minn=100000000;
    int flag=0;
    //cout<<dir[5][1];
    for(int j=0;j<6;j++){
        int count=0;
        for(int i=0;i<n;i+=3){
            if(s[i]!=dir[j][0]) count++;
            if(i+1 >= n)
            break;
            else if(s[(i+1)]!=dir[j][1]) count++;
            if(i+2 >= n)
            break;
            else if(s[(i+2)]!=dir[j][2]) count++;
        }
        if(count<minn){
            minn=count;
            flag=j;
        }
    }
    cout<<minn<<endl;
    int i;
    for(i=0;i + 3 <n;i+=3){
        cout<<dir[flag];
    }
    int j = 0;
    for(i;i < n;i++)
    cout << dir[flag][j++];
    
    //if(n%3==)
    return 0;
}//比赛结束了几分钟才改好,emmmmmmm,笨死啦。

CF 959 E. Mahmoud and Ehab and the xor-MST

CF 959 E. Mahmoud and Ehab and the xor-MST

E. Mahmoud and Ehab and the xor-MST

https://codeforces.com/contest/959/problem/E

分析:

  每个点x应该和x ^ lowbit(x)连边,那么现在就是求$\sum_{i=1}^{n}lowbit(i)$,然后打表找规律。

代码:

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<cmath>
 6 #include<cctype>
 7 #include<set>
 8 #include<queue>
 9 #include<vector>
10 #include<map>
11 using namespace std;
12 typedef long long LL;
13 
14 inline int read() {
15     int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch==''-'')f=-1;
16     for(;isdigit(ch);ch=getchar())x=x*10+ch-''0'';return x*f;
17 }
18 
19 int main() {
20     LL n, res = 0;
21     cin >> n; n--;
22     for (LL x = 1; x <= n; x <<= 1) 
23         res += ((n - x) / (x + x) + 1) * x;
24     cout << res;
25     return 0;
26 }

 

CF959E Mahmoud and Ehab and the xor-MST 思维

CF959E Mahmoud and Ehab and the xor-MST 思维

Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n?-?1. For all 0?≤?u?<?v?<?n,vertex u and vertex v are connected with an undirected edge that has weight

分享图片

(where

分享图片

is the bitwise-xor operation). Can you find the weight of the minimum spanning tree of that graph?

You can read about complete graphs in https://en.wikipedia.org/wiki/Complete_graph

You can read about the minimum spanning tree in https://en.wikipedia.org/wiki/Minimum_spanning_tree

The weight of the minimum spanning tree is the sum of the weights on the edges included in it.

Input

The only line contains an integer n (2?≤?n?≤?1012),the number of vertices in the graph.

Output

The only line contains an integer x,the weight of the graph‘s minimum spanning tree.

Example
Input
copy
4
Output
copy
4
Note

In the first sample:

分享图片

The weight of the minimum spanning tree is 1+2+1=4.

 

题意翻译

n个点的完全图标号(0-n-1),i和j连边权值为i^j,求MST的值

 

不妨先手算几项,可以发现每一位上的贡献为当前n 的一半;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 300005
#define inf 0x3f3f3f3f
#define INF 9999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int,int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)

inline ll rd() {
	ll x = 0;
	char c = getchar();
	bool f = false;
	while (!isdigit(c)) {
		if (c == ‘-‘) f = true;
		c = getchar();
	}
	while (isdigit(c)) {
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return f ? -x : x;
}

ll gcd(ll a,ll b) {
	return b == 0 ? a : gcd(b,a%b);
}
ll sqr(ll x) { return x * x; }

/*ll ans;
ll exgcd(ll a,ll b,ll &x,ll &y) {
	if (!b) {
		x = 1; y = 0; return a;
	}
	ans = exgcd(b,a%b,x,y);
	ll t = x; x = y; y = t - a / b * y;
	return ans;
}
*/



ll qpow(ll a,ll c) {
	ll ans = 1;
	a = a % c;
	while (b) {
		if (b % 2)ans = ans * a%c;
		b /= 2; a = a * a%c;
	}
	return ans;
}



int main()
{
	//ios::sync_with_stdio(0);
	ll n; rdllt(n);
	ll ans = 0;
	ll tmp = 1;
	while (n>1) {
		ans += tmp * (n >> 1); tmp <<= 1; n -= (n >> 1);
	//	cout << n<<‘ ‘<<ans << endl;
	}
	cout << ans << endl;
    return 0;
}

Codeforces #396 (Div. 2) D. Mahmoud and a Dictionary (并查集+map

Codeforces #396 (Div. 2) D. Mahmoud and a Dictionary (并查集+map

总结

以上是小编为你收集整理的Codeforces #396 (Div. 2) D. Mahmoud and a Dictionary (并查集+map全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

今天关于Codeforces Round #435 (Div. 2)C. Mahmoud and Ehab and the xor(异或的性质)异或结果的讲解已经结束,谢谢您的阅读,如果想了解更多关于B类-Codeforces Round #535 (Div. 3)C. Nice Garland、CF 959 E. Mahmoud and Ehab and the xor-MST、CF959E Mahmoud and Ehab and the xor-MST 思维、Codeforces #396 (Div. 2) D. Mahmoud and a Dictionary (并查集+map的相关知识,请在本站搜索。

本文标签: