标签:div 自己的 自己 代码 code eth efi include false
时间复杂度O(nlogn)
#include<bits/stdc++.h>
const int maxn=200020;
#define ll long long
int a[maxn];
int mod[maxn];
int ka[maxn];
int n,k;
int geth(int x){
ll mul=1;
int t=1;
while(mul<=x){
mul=mul*10;
t=(t*(10%k))%k;
}
return t;
}
int main(){
scanf("%d %d",&n,&k);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
mod[i]=a[i]%k;
ka[i]=(geth(a[i]))%k;
}
ll ans=0;
for(int i=1;i<=n;i++){//O(n^2)
for(int j=1;j<=n;j++){
if(i!=j&&((mod[i]*(ka[j]))%k+mod[j])%k==0){
//printf("db %d %d\n",i,j);
ans++;
}
}
}
printf("%I64d\n",ans);
}
这道题还没想出来,据说使用贪心,下面是别人代码(感觉大佬的思路都是一样,应该是触摸到问题本质)
#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;
}
枚举较短边,考虑蓝方块构成矩形的最低高度和红方块构成矩形的最低高度是否和当前高度冲突
#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;
}
Codeforces Round #506 (Div. 3) D-F
标签:div 自己的 自己 代码 code eth efi include false
原文地址:https://www.cnblogs.com/fridayfang/p/9536123.html