Codeforces Round #506 (Div. 3) (中等难度)

自己的做题速度大概只尝试了D题,不过TLE

D. Concatenated Multiples

题意

  • 数组a[],长度n,给一个数k,求满足条件的(i,j)(i!=j) a[i],a[j]连起来就可以整除k
  • 连起来的意思是 20,5连起来时205; 5,20连起来时520
  • n<=2*1e5,k<=1e9,ai<=1e9
  • 愚蠢的思路是像我一样遍历(i,j)可能性,然后TLE,因为这是O(n^2)
  • 可以先思考一简单问题如何不是连起来而是a[i]+a[j]如何计算,很简单将a[]%k进行计数,然后计数(k-a[i])%k,这时查找只需O(logn)
  • 这里a[i]*(10^k),k实际上只有10中可能所以也可以存起来
  • 时间复杂度O(nlogn)

代码

#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
int a[200005],le[200005];
map<int,int> dp[15];
int main(){
int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
int tmp=a[i];
while(tmp){
le[i]++;
tmp/=10;
}
dp[le[i]][a[i]%k]++;//dp[len][res] len是1...10 res [0...k-1]
//res由于是map存储大概是O(nlogn)
}
ll ans=0;
for(int i=1;i<=n;i++){//个数遍历所有a[i]然后找到统计match:a[i]*(10^le[j])+a[j]的j的个数
dp[le[i]][a[i]%k]--;//是指统计时刨除自身
ll mul=1,tmp=0;
for(int j=1;j<=10;j++){
mul*=10;
tmp=mul*a[i];
int rem = (k-tmp%k)%k;
if(dp[j].count(rem)) ans+=dp[j][rem]; }
dp[le[i]][a[i]%k]++; }
cout<<ans<<endl;
}

E. Tree with Small Distances

题意

  • 这道题还没想出来,据说使用贪心,下面是别人代码(感觉大佬的思路都是一样,应该是触摸到问题本质)

代码

#include<bits/stdc++.h>
using namespace std; int n;
const int maxn = 2e5+100;
vector<int> G[maxn];
int used[maxn];
int d[maxn];
int ans = 0; void dfs(int u,int f){
//cout<<"enter"<<u<<" "<<f<<endl;
bool flag = false;
for(int i=0;i<G[u].size();i++){
int v = G[u][i];
if(v!=f){
d[v] = d[u] + 1;
dfs(v,u);
flag|=used[v];
}
}
if(d[u]>2&&!used[u]&&!flag&&!used[f]){
used[f] = true;
//cout<<"db"<<f<<endl;
ans++;
}
//cout<<"out"<<endl;
} int main(){
int t;
//freopen("in.txt","r",stdin);
scanf("%d",&n);
for(int i=0;i<n-1;i++){
int a,b;
scanf("%d%d",&a,&b);
G[a].push_back(b);
G[b].push_back(a);
}
dfs(1,0);
/*
cout<<"db1\n";
for(int i=1;i<=n;i++){
cout<<d[i]<<"\t";
}
cout<<endl;
for(int i=1;i<=n;i++){
cout<<used[i]<<"\t";
}
cout<<"db over"<<endl;
*/
printf("%d\n",ans);
//fclose(stdin);
return 0;
}

F. Multicolored Markers

题意

  • 自己看
  • 枚举较短边,考虑蓝方块构成矩形的最低高度和红方块构成矩形的最低高度是否和当前高度冲突

代码

#include<bits/stdc++.h>
#define ll long long int main(){
ll a,b;
std::cin>>a>>b;
ll c=a+b;
ll tmp=std::max(a,b);
ll minl=(a+b+1)*2;
ll lowa=a;
ll lowb=b;
for(ll i=1;i*i<=(a+b);i++){
if(a%i==0) lowa=a/i;
if(b%i==0) lowb=b/i;
if(c%i==0){
if(c/i>=lowa||c/i>=lowb){
//std::cout<<"db"<<i<<std::endl;
minl=std::min(2*(i+c/i),minl);
}
}
}
std::cout<<minl<<std::endl;
}

加油,需要补题Kmp,数论+树

Codeforces Round #506 (Div. 3) D-F的更多相关文章

  1. Codeforces Round #506 (Div. 3) 1029 F. Multicolored Markers

    CF-1029F 题意: a,b个小正方形构造一个矩形,大小为(a+b),并且要求其中要么a个小正方形是矩形,要么b个小正方形是矩形. 思路: 之前在想要分a,b是否为奇数讨论,后来发现根本不需要.只 ...

  2. Codeforces Round #506 (Div. 3) 题解

    Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...

  3. Codeforces Round #506 (Div. 3) E

    Codeforces Round #506 (Div. 3) E dfs+贪心 #include<bits/stdc++.h> using namespace std; typedef l ...

  4. Codeforces Round #573 (Div. 1) 差F

    Codeforces Round #573 (Div. 1) E 题意:二维平面上有 n 个点,你可以放至多 m 条直线使得 (0,0) 与每个点的连线至少与一条直线相交.求原点与所有直线的距离最小值 ...

  5. Codeforces Round #541 (Div. 2) (A~F)

    目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...

  6. Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)

    F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...

  7. Codeforces Round #600 (Div. 2)E F

    题:https://codeforces.com/contest/1253/problem/E 题意:给定n个信号源,俩个参数x和s,x代表这个信号源的位置,s代表这个信号源的波及长度,即这个信号源可 ...

  8. Codeforces Round #346 (Div. 2) E F

    因为很久没有个人认真做题了 昨天晚上开了场虚拟cf来锻炼个人手速 选的是第一次做cf的场 那时候7出3还被hack...之后也没补题 这次做的时候顺便回忆了一下以前比赛的时候是怎么想的 发现经验还是很 ...

  9. Codeforces Round #506 (Div. 3)

    题解: div3水的没有什么意思 abc就不说了 d题比较显然的就是用hash 但是不能直接搞 所以我们要枚举他后面那个数的位数 然后用map判断就可以了 刚开始没搞清楚数据范围写了快速乘竟然被hac ...

随机推荐

  1. BZOJ 1355: [Baltic2009]Radio Transmission AC自动机/KMP

    被一个KMP傻题搞蒙圈了,此题AC自动机空间超限,只能用KMP写(我只会AC自动机QAQ)...... AC自动机 Code: // luogu-judger-enable-o2 #include & ...

  2. 64 求1+2+3+...+n(发散思维能力 )

    题目描述: 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 解题思路: 1)利用&&的短 ...

  3. 01.Python基础-1.Python简介及基础

    python简介 python简介 python是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum(吉多·范罗苏姆)于1989年发明,第一个公开发行版发行于1991年. ...

  4. TensorFlow实现LeNet5模型

    # -*- coding: utf-8 -*-import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_ ...

  5. tomcat 内存溢出问题(OutOfMemoryError: PermGen space)

    导入公司项目的时候出现的问题,在此记录处理方法. tomcat在启动的时候报错:OutOfMemoryError: PermGen space PermGen space的全称是Permanent G ...

  6. hdu 1385 floyd记录路径

    可以用floyd 直接记录相应路径 太棒了! http://blog.csdn.net/ice_crazy/article/details/7785111 #include"stdio.h& ...

  7. BA-给排水-供水系统自动控制(转载)

    浙江省建筑设计研究院划 杨绍胤 杨庆 摘 要:探讨供水系统变流量和恒压自动控制和设计方法.关键词: 供水系统 自动控制 传统给水系统常在屋顶设置高位水箱.水从地下水箱用水泵打到高位水箱.从高位水箱通过 ...

  8. [HTML5] Semantics for accessibility

    For example, when we use checkbox, if we do like this: <div class="inline-control sign-up co ...

  9. How to improve Java&#39;s I/O performance( 提升 java i/o 性能)

    原文:http://www.javaworld.com/article/2077523/build-ci-sdlc/java-tip-26--how-to-improve-java-s-i-o-per ...

  10. JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xfe

    JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xfe 在使用Jni ...