CodeForces 776D The Door Problem【并查集】并查集 设 f 1--m 表示 开的情况 m+1--2*m 表示关的情况 对于每盏灯 如果他 是关的 则 x--y x+m--y+m 表示要同关 或者同开 如果他 是开的 则 x+m--y x--y+m 表示一个关 一个开如果一盏灯 的 x 连向 了 x+m 则表示是矛盾了 那么久是错误的 题意:给你n个门,和m组开关,每扇门都有两个开关控制,每个开关控制x扇门,如果选择了某组开关,则使这组开关里的每个开关控制...
题目链接:Codeforces Round #373 (Div. 2)分析:只补了B,C,其他题再看看,做出几道说几道,QAQ B题有两种操作,一种是交换两个字母的位置,另一种是改变字母,使得最后序列成为一个形如drdrd/rdrdr的序列。在两种情况中取较小值。 我将奇数与偶数次位置分开处理,如果交换,则两个都加一;如果改变字母,则对应的奇/偶位置++,取两者较大者。详情见代码: 1 #include<cstdio>2 #include<cstring>3 #include<algorith...
考完雅思了开始康复训练...争取以后每把都打不咕。A.Odd DivisorEditorial:偶数有个特性就是可以一直除2,所以我们只需要判断无限除2之后的奇数是不是1即可。#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl ‘\n‘
#define eps 0.000000001
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)...
题意:就是挖地雷,给你一个字符串,‘*’代表地雷,‘1’代表在它的周围有1个地雷,‘2’代表在左右都有个地雷,‘?’代表不确定是不是地雷,可以是1,2,*,问你最后有几种方式确定所有的的地雷。思路:dp[i][0] 代表次位置为0,dp[i][1]代表左边有地雷,dp[i][2]代表右边有地雷,dp[i][3]代表左右都有,dp[i][4]代表此位置为地雷。 1 #include <cstdio>2 #include <cstring>3 #include <algorithm>4#define maxn 10001005#defi...
总算又能安心刷题了
A. Nastia and Nearly Good Numbers
题意:
给定A、B,要求找出三个数 x,y,z。满足条件:
x + y = z其中有两个数只能整除A,有一个可以整除A*Bx,y,z 各不相同
思路:
显然,z是最大的,让z整除A*B就行了 。 那么令 x = A*(B-1) , y = A , z = A*B 就行了。 这个时候,可以发现,B不能等于1,同时当B等于2的时候,x 和 y 相等。那么可以令 x = 3A ,y = A ,z = 4A。
Code:
#include <bits/stdc++.h>
#defi...
#include <bits/stdc++.h>
#define priority_queue < ll, std::vector<ll>, std::greater<ll> > mnheap;
#define REP(i,a,b) for (auto i = a; i != b; i++)
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define eb emplace_back
#define f first
#define s second
#define pb push_back
using nam...
Codeforces Round #402 (Div. 2) A.日常沙比提#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
usingnamespace std;
inline int read(){char c=getchar();int x=0,f=1;while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1; c=getchar();}while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘; c=getchar();}return x*f;
}
int n,a[10],b[10],ans;
int main(){//freopen("in","r",stdin);n=read();for(int...
链接:https://codeforces.com/contest/1241/problem/B题意:You are given two strings of equal length s and t consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice versa.For example, if s is "acbc" ...
卡题意……妈的智障一个人的服务时间完整包含在整个工作时间以内。显然,如果有空档的时间,并且能再下班之前完结,那么直接输出即可,显然取最左侧的空档最优。如果没有的话,就要考虑“挤掉”某个人,就是在某个人之前1分钟到达,这样显然比较优。就这些情况都考虑上就得了。#include<cstdio>
using namespace std;
typedef long long ll;
ll ts,tf,t,a[100010],b[100010],wait=10000000000000ll,ans;
int n,num[100010],m;
int ...
点这里进原题
A. The Child and Homework题目大意
张三要做题,题目有ABCD四个选项,如果其最长的选项大于其他所有选项的长度的2倍或最短的选项小于其他所有选项的长度的1/2,那张三就选这个选项,如果不是就选 C。 这个张三就是逊啦!解析
我的思路是先遍历四个选项找出最大的最小的,再遍历一遍判断是否符合题目条件,值得注意的是如果最长最短都符合的话也是要选C的 。(可能是因为张三不知道蒙哪个了吧)AC CODE
#include <iostr...
蛋疼的比赛,当天忘了做了,做的模拟,太久没怎么做题了,然后C题这么简单的思路却一直卡到死,期间看了下D然后随便猜了下,暴力了下就过了。A.找一个能被t整除的n位数,那么除了<=10以外,其他都可以用长度为n的10或100,1000 。。。 来往上加几个数而得到#include <iostream>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <string.h>
usingnamespace std;int getwei(int x)
{int sum=0;while(x){sum++;x=x/1...
比赛链接:http://codeforces.com/contest/148比较简单的一场,最长的一题也才写了30行多一点A. Insomnia curetime limit per test:2 secondsmemory limit per test:256 megabytes?One dragon. Two dragon. Three dragon?, — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.However, just counting dragons was boring as well, so she entertained herse...
题目类型:位运算传送门:>Here<题意:求区间\([L,R]内二进制中1的个数最多的那个数,如果有多解输出最小解\)解题思路想了15min就一遍A了我们可以贪心地在\(L\)的基础上+1,从小的往大的加。根据二进制的性质,我们不可能把原来的1变成0,除非在更高位搞出一个新的1来。因为如果不在更高位搞出一个1,就肯定比\(L\)小了。而我们又不可能搞掉一个地位,去弄一个高位,因为这样不仅没有让1的个数增多,反而让数字更大了因此我们的最优...
Ivan has an array consisting of n different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into one sorted array.Ivan represent his array with increasing sequences with help of the following algorithm.While there is at least one unused number in array ...
Journey题意:给一颗树,边权都为1,从1出发,求走到叶子节点的边权和的期望(每次往孩子遍历的等概率的)思路:从1出发dfs,每个点到下一个点的概率是当前节点的概率乘孩子节点的个数,也就是当前点的边数-1,到叶子节点后计算概率乘边权和然后相加就是了,1节点需要特殊处理一下AC代码:#include "iostream"
#include "iomanip"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#in...