Codeforces Beta Round 84 (Div. 2 Only)
layout: post
title: Codeforces Beta Round 84 (Div. 2 Only)
author: "luowentaoaa"
catalog: true
tags:
mathjax: true
- codeforces
传送门
不得不说这远古场太简单了
A - Nearly Lucky Number (签到)
题意
给出一个数字 求其中7和4的数目是否是7和4组成
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
const int maxn=3e5+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
string s;
cin>>s;
int len=s.size();
int sum=0;
for(int i=0;i<len;i++){
if(s[i]=='4'||s[i]=='7'){
sum++;
}
}
if(sum==4||sum==7){
cout<<"YES"<<endl;
}
else cout<<"NO"<<endl;
return 0;
}
B - Lucky String(贪心构造)
题意
让你构造一个字典序最小字符串 其中每个字符之间的间隔都必须是4和7组成的幸运数字
思路
直接ABCD四个一循环就行
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
const int maxn=3e5+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
char s[5]={'a','b','c','d'};
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n;
cin>>n;
for(int i=0;i<n;i++){
cout<<s[i%4];
}
return 0;
}
C - Lucky Sum of Digits (构造)
题意
给出一个N问你能否存在一个由4和7组成并且各位之和为N的数字并且各位之和为N的数字
有输出最小的 没有输出-1
思路
7×A+4×B=N
要最小 那就是长度最短 所以经可能让7多
因为数据1e6 直接枚举时间过得去
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
const int maxn=3e5+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
char s[5]={'a','b','c','d'};
int seven,four;
string ans="999";
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n;
cin>>n;
bool flag=0;
for(int i=0;i<=n/7;i++){
int fo=n-i*7;
if(fo%4==0){
seven=i;
flag=1;
four=fo/4;
}
}
if(!flag)cout<<-1;
else{
for(int i=0;i<four;i++){
cout<<4;
}
for(int i=0;i<seven;i++)
cout<<7;
}
return 0;
}
D - Lucky Probability (区间枚举)
题意
出个两个(P,V)范围在1e9的正整数区间,分别从其中随机选出一个数,选出的两个数作为一个新区间的左右端点。要求新区间内的幸运数刚好为k个的概率(幸运数指一个数的数位只有4或7)。
思路
直接做肯定爆炸,我们发现1e9范围内最多2^10个幸运数字
然后我们就直接判断幸运数字 的区间,使得一个在min,一个在max
注意就是K==1的时候要去重一下
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
const int maxn=3e5+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
ll has[maxn];
int num=0;
ll get(ll al,ll ar,ll ql,ll qr){
ll l=max(al,ql);
ll r=min(ar,qr);
return l<=r?(r-l+1LL):0;
}
vector<ll>pre,nex;
void init(){
pre.push_back(0);
for(int i=0;i<10;i++){
nex.clear();
for(auto i:pre){
ll now=i*10LL+4LL;
nex.push_back(now);
has[++num]=now;
now=i*10LL+7LL;
nex.push_back(now);
has[++num]=now;
}
pre=nex;
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
init();
ll pl,pr,vl,vr,k;
cin>>pl>>pr>>vl>>vr>>k;
ll down=1LL*(pr-pl+1LL)*(vr-vl+1LL);
ll ans=0;
for(ll i=1;i<=2040;i++){
ll pre=i,next=i+k-1;
ans+=get(has[pre-1]+1,has[pre],pl,pr)*get(has[next],has[next+1]-1,vl,vr);
ans+=get(has[pre-1]+1,has[pre],vl,vr)*get(has[next],has[next+1]-1,pl,pr);
}
if(k==1){
for(int i=1;i<=2040;i++){
ans-=get(has[i],has[i],pl,pr)*get(has[i],has[i],vl,vr);
}
}
cout<<fixed;
cout<<setprecision(13)<<double(ans*1.0/down*1.0)<<endl;
return 0;
}
E - Lucky Tree(并查集)
题意
给你一个树,让你求有多少个三元组(a,b,c)满足a,b,c不同并且a到b至少有一个为幸运数字的边 a到c之间也至少有一个幸运数字的边
问这个三元组有多少个
思路
首先 没有幸运数字为边的点可以缩成一个点,因为他们之间肯定不能连线对答案没有贡献
这时候其他的点就和这个点相连就有贡献了
所以直接并查集缩点就行
比赛题目没看完就结束了 难过
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
int fa[maxn],sz[maxn];
int find(int x){
return x==fa[x]?x:fa[x]=find(fa[x]);
}
void fix(int a,int b){
a=find(a),b=find(b);
if(sz[a]>sz[b])swap(a,b);
sz[b]+=sz[a];
sz[a]=0;
fa[a]=b;
}
bool luck(int x){
while(x){
if(x%10!=4&&x%10!=7)return false;
x/=10;
}
return true;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)sz[fa[i]=i]=1;
for(int i=1;i<n;i++){
int a,b,c;
cin>>a>>b>>c;
if(!luck(c))fix(a,b);
}
ll ans=0;
for(int i=1;i<=n;i++){
if(sz[i]){
ans+=1LL*(sz[i])*(1LL*n-sz[i])*(n-sz[i]-1LL);
}
}
cout<<ans;
return 0;
}
Codeforces Beta Round 84 (Div. 2 Only)的更多相关文章
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)
A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
随机推荐
- [洛谷P4291][HAOI2008]排名系统
题目大意:三种操作: $+Name\;Socore:$上传最新得分记录,把以前的记录删除. $?Name:$ 查询玩家排名.如果两个玩家的得分相同,则先得到该得分的玩家排在前面. $?Index:$ ...
- [洛谷P4124][CQOI2016]手机号码
题目大意:给你两个$l,r$,求出$[l,r]$中符合要求的数,要求为至少有$3$个相邻的相同数字,且不可以同时出现$8$和$4$ 题解:数位$DP$ 卡点:无 C++ Code: #include ...
- [NOIP2017 TG D2T2]宝藏
题目大意:给定一个有重边,边有权值的无向图.从某一个点出发,求到达所有的点需要的最少费用,并且限制两点之间只有一条路径.费用的计算公式为:所有边的费用之和.而边$x->y$的费用就为:$y$到初 ...
- AtCoder Code Festival 2017 Team Relay J - Indifferent
题目大意:共$2n$个价格$p_i$.两人轮流取.你每次取最大的,对方每次随机取.问你取的期望和是多少. 题解:从小到大排序,$\sum\limits_{i=0}^{2n-1} \frac{i*p_i ...
- [Leetcode] unique paths 独特路径
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- sqlserver数据库迁移
本篇我们将利用DMA一步一步实现SQL Server 的迁移.帮助大家理解现在的SQL Server与新版本的融合问题,同时需要我们做哪些操作来实现新版本的升级或者迁移. SQL Server 迁移 ...
- CDQZ 2017 游记
Day0: 提前放了一整天假,颓过去了.老吕让我去给B层的讲课,ppt还没做,只能在飞机上赶了QAQ.然后从上午到了衡水就一直在路上或者天上,到了晚上才到学校,然而ppt还是没有做完.还有,鄂尔多斯真 ...
- MySQL的字符集小结
正确了解MySQL的字符集问题,能够从根本上解决乱码的困扰. 首先,MySQL的字符集问题主要是两个概念,一个是Character Sets,一个是Collations,前者是字符内容及编码,后者是对 ...
- [hdu 3949]线性基+高斯消元
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 一开始给做出来的线性基wa了很久,最后加了一步高斯消元就过了. 之所以可以这样做,证明如下. 首 ...
- WebComponents001
Sample1: ShadowDom 隔离style,替换显示内容 <button>Hello, world!</button> <script> var host ...