当前位置:网站首页>Codeworks round 680 div2
Codeworks round 680 div2
2022-06-11 08:40:00 【Kath_ one thousand and thirty-one】
https://codeforces.com/contest/1445
A thinking
#include<bits/stdc++.h>
using namespace std;
const int maxn=60;
int a[maxn],b[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,x;
scanf("%d%d",&n,&x);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
scanf("%d",&b[i]);
sort(a+1,a+n+1);
sort(b+1,b+n+1);
bool success=true;
for(int i=1;i<=n;i++)
{
if(a[i]+b[n-i+1]>x)
{
success=false;
break;
}
}
if(success)printf("Yes\n");
else printf("No\n");
}
}B thinking
Minimum case 100 people a+b,100 people d+c
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
printf("%d\n",max(a+b,d+c));
}
}C Eulerian sieve back to q Decomposing the prime factor
Consider special column p Itself cannot be q to be divisible by .
Think again p Can be q to be divisible by , signify p The exponent of all prime factors in is greater than q Of the prime number corresponding to the prime factor in . Try writing on paper p and q The prime factorization of .
So just let p The exponent of a prime factor is less than q The corresponding quality factor index of . The next step is to simply enumerate prime factors .
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int prime[maxn],cnt;
bool st[maxn];
void init()
{
for(int i=2;i<maxn;i++)
{
if(!st[i])prime[cnt++]=i;
for(int j=0;prime[j]*i<maxn;j++)
{
st[prime[j]*i]=true;
if(i%prime[j]==0)break;
}
}
}
ll get(ll p,int q,int prim)
{
while(p%q==0)
p/=prim;
return p;
}
int main()
{
int T;
scanf("%d",&T);
init();
while(T--)
{
ll p,q;
cin>>p>>q;
ll res=0;
int t=q;
for(int i=0;i<cnt;i++)
if(t%prime[i]==0)
{
while(t%prime[i]==0)t/=prime[i];
res=max(res,get(p,q,prime[i]));
// cout<<prime[i]<<endl;
}
if(t>1)res=max(res,get(p,q,t));
cout<<res<<endl;
}
}D thinking , Combinatorial number
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
typedef long long ll;
ll a[maxn];
const int p=998244353;
int qmi(int a, int k)
{
int res = 1;
while (k)
{
if (k & 1) res = (ll)res * a % p;
a = (ll)a * a % p;
k >>= 1;
}
return res;
}
int C(int a, int b)
{
if (a < b) return 0;
int down = 1, up = 1;
for (int i = a, j = 1; j <= b; i --, j ++ )
{
up = (ll)up * i % p;
down = (ll)down * j % p;
}
return (ll)up * qmi(down, p - 2) % p;
}
int Lucas(int a, int b)
{
if (a < p && b < p) return C(a, b);
return (ll)Lucas(a / p, b / p) * C(a % p, b % p) % p;
}
int main()
{
int n;
scanf("%d",&n);
int nn=n+n;
for(int i=1;i<=nn;i++)scanf("%lld",&a[i]);
sort(a+1,a+nn+1);
ll res=0;
for(int i=1;i<=n;i++)
res+=a[i+n]-a[i];
res=(res+p)%p;
res=res*Lucas(2*n,n)%p;
cout<<res<<endl;
}E This question debug For a long time , Finally, I found out after reading other people's solutions
Post a link to the solution https://www.cnblogs.com/George1123/p/13912680.html
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define mp(a,b) make_pair((a),(b))
#define x first
#define y second
const int maxn=5e5+10;
struct node
{
int p[maxn],dep[maxn];
int find(int x)
{
if(p[x]!=x)
{
int nex=find(p[x]);
dep[x]^=dep[p[x]];
p[x]=nex;
}
return p[x];
}
}d[2];
map<pii,int> mp;
pii me[maxn];
vector<pii> e[maxn];
int cnt;
int c[maxn];
int n,m,k;
bool st[maxn];
int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=0;i<n;i++)
{
scanf("%d",&c[i]);c[i]--;
}
while(m--)
{
int a,b;
scanf("%d%d",&a,&b);
a--,b--;
if(c[a]>c[b])swap(a,b);
pii t=mp(c[a],c[b]);
if(!mp.count(t))
{
mp[t]=cnt;
me[cnt]=t;
cnt++;
}
e[mp[t]].push_back({a,b});
}
iota(d[0].p,d[0].p+n,0);
ll res=k;
for(int i=0;i<k;i++)
if(mp.count(mp(i,i)))
{
for(pii t:e[mp[mp(i,i)]])
{
int x=d[0].find(t.x),y=d[0].find(t.y);
if(x==y&&d[0].dep[t.x]^d[0].dep[t.y]==0)
{
res--;
st[i]=true;
break;
}
d[0].dep[x]=d[0].dep[t.y]^1^d[0].dep[t.x];
d[0].p[x]=y;
}
}
res=res*(res-1)/2;
for(int i=0;i<cnt;i++)
{
if(me[i].x==me[i].y)continue;
if(st[me[i].x]||st[me[i].y])continue;
for(auto t:e[i])
{
int xi=d[0].find(t.x),yi=d[0].find(t.y);
d[1].dep[xi]=0,d[1].dep[yi]=0;
d[1].p[xi]=xi,d[1].p[yi]=yi;
}
for(auto t:e[i])
{
int xi=d[0].find(t.x),yi=d[0].find(t.y);
int x=d[1].find(xi),y=d[1].find(yi);
if(x==y&&d[1].dep[xi]^d[1].dep[yi]^d[0].dep[t.x]^d[0].dep[t.y]==0)
{
res--;
break;
}
d[1].dep[x]=d[1].dep[xi]^d[1].dep[yi]^d[0].dep[t.x]^d[0].dep[t.y]^1;
d[1].p[x]=y;
}
}
cout<<res<<endl;
}边栏推荐
- [software tool] the hacker matrix special effect software CMatrix
- 这几个小工具也太好用了
- Node error report sorting
- Interprocess communication
- [software tools] screen recording software captura
- AttributeError: module ‘tensorflow. compat. v2.__ internal__‘ has no attribute ‘register_ clear_ session_
- What is concurrent search set? Are you still worried about it? In fact, it is a problem of connected graph, which is not so difficult to understand
- Use of Excel to XML tool of TestLink
- Bat batch processing separate environment packaging
- Introduction to database system experiment report answer Experiment 6: advanced query of data table
猜你喜欢

B+ super tree helps you know the underlying structure of MySQL

Web design and website planning assignment 12 online registration form

Empty difference between postgrepsql and Oracle

Anaconda+tensorflow most effective summary version (blood and tears summary of 6 reloads)

Typescript header file usage details

结果和目标出入太大?不妨借助目标管理精准直达目标!

(resolved) typeerror: meshgrid() got an unexpected keyword argument 'indexing‘

进程控制:进程等待(回收子进程)

(the slow download speed of cifar10 in torchvision has been solved) how to download and use torchvision import

Multiple limit of the same field of SQL
随机推荐
堆是也可以看成一种树结构,规定根节点必须大于或小于左右子节点,但左右子节点的大小顺序没有规定
Basic use of typescripy class
(resolved) typeerror: meshgrid() got an unexpected keyword argument 'indexing‘
Reference implementation scheme of database database and table division strategy
Implementation of CRF for named entity recognition
用飞项进行目标管理,不做职场上的“无头苍蝇”
Idea pulls items from remote warehouse
SSM file upload and download
Development of sylixos SD device driver
进程控制:进程等待(回收子进程)
项目实训-克隆门
Typescript type alias
bat 批处理单独环境打包
命名实体识别之CRF的实现方式
The difference between & & and &
Solve cannot import name 'multiheadattention' from 'tensorflow keras. layers‘
Heap can also be regarded as a tree structure. It is specified that the root node must be greater than or less than the left and right child nodes, but the size order of the left and right child nodes
torch. unbind()
Use Jackson's @jsonproperty annotation to add one more field to the property name. Solution to the problem
Introduction to database system experiment report answer Experiment 5: database single table query