http://codeforces.com/contest/1184

A1

找一对整数,使x^x+2xy+x+1=r

变换成一个分式,保证整除

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include <map>
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define ll long long
using namespace std;
const int maxn = ;
const ll mod = 1e9+;
inline ll read(){
ll x = , f = ;
char ch = getchar();
while (ch < '' || ch > ''){
if (ch == '-')
f = -;
ch = getchar();
}
while (ch >= '' && ch <= ''){
x = x * + ch - '';
ch = getchar();
}
return x * f;
}
ll r;
int main(){
r=read();
for(ll i = ;i <= ;i++){
if(i*i>r)break;
ll t = r-i*i-i-;
if(t<=)continue;
if(t%(i+i)==){
cout<<i<<" "<<t/(i+i);
return ;
}
}
cout<<"NO";
return ;
}

A2

给定一个二进制串,对于整数k来说,若存在另一个二进制串x,时x与x右移k位异或的结果等于这个二进制串,k就是合法的,求合法的k的数量。

先考虑x,第一个位确定了,后面1+k,1+2k...的位也确定了,最后会回到第一位,这时需要与之前假定的第一位一致。于是这就形成了一个循环。循环长度为lcm(k,n)/k=n/gcd(k,n)。

对k,按gcd(k,n),进行归纳求解,将所有k映射到gcd(k,n),然后求出gcd(k,n)的答案,只需要遍历所有循环的位置,再查看是否合法。

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include <map>
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define ll long long
using namespace std;
const int maxn = ;
const ll mod = 1e9+;
inline ll read(){
ll x = , f = ;
char ch = getchar();
while (ch < '' || ch > ''){
if (ch == '-')
f = -;
ch = getchar();
}
while (ch >= '' && ch <= ''){
x = x * + ch - '';
ch = getchar();
}
return x * f;
}
int n;
int a[maxn];
char s[maxn];
bool vis[maxn];
bool can[maxn];
int gcd(int a,int b){
return b==?a:gcd(b,a%b);
}
int main(){
n=read();
scanf("%s",s+);
fo(i,,n){
a[i] = s[i] - '';
}
int ans = ,tot = ;
fo(i,,n){
int g = gcd(i,n);
if(vis[g]){
ans += can[g];
}else{
vis[g]=true;
bool ok=false;
fo(j,,g){
ok=true;
tot=;
for(int k = j;k <= n;k += g){
tot += a[k];
}
if(tot%){
ok=false;
break;
}
}
if(ok) can[g]=true;
ans += can[g];
}
}
cout<<ans;
return ;
}

B1

舰队攻打敌军,只能攻打防御力不大于它攻击力的,敌军掉落的金币不等,问每个船能打多少钱

排序即可

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include <map>
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define ll long long
using namespace std;
const int maxn = ;
const ll mod = 1e9+;
inline ll read(){
ll x = , f = ;
char ch = getchar();
while (ch < '' || ch > ''){
if (ch == '-')
f = -;
ch = getchar();
}
while (ch >= '' && ch <= ''){
x = x * + ch - '';
ch = getchar();
}
return x * f;
}
int s,b;
struct dat{
int pos;
int val;
friend bool operator < (dat a,dat b){
return a.val < b.val;
}
}shp[maxn],ene[maxn];
ll gold[maxn];
int main(){
s=read();
b=read();
fo(i,,s){
shp[i].pos=i;
shp[i].val=read();
}
fo(i,,b){
ene[i].val=read();
ene[i].pos=read();
}
sort(shp+,shp++s);
sort(ene+,ene++b);
int pos=;
ll ans = ;
fo(i,,s){
while(pos<b&&ene[pos+].val<=shp[i].val){
pos++;
ans += ene[pos].pos;
}
gold[shp[i].pos]=ans;
}
fo(i,,s){
printf("%I64d ",gold[i]);
}
return ;
}

B2

敌军在一个图上攻打舰队,每个敌军只能打防御力不大于他的船,并且两者距离不大于他的燃油量。每个敌军负责打一个人,掠夺k金币。

我军可以花h金币建造假船,一定会被一个敌军攻击,且不损失金币。求损失最少的策略。

因为金币数量是固定的,容易证明要么全用假船吸引,要么一个假船都不放。

先跑多源最短路,然后匹配即可。

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include <map>
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define ll long long
using namespace std;
const int maxn = ;
const ll mod = 1e9+;
inline ll read(){
ll x = , f = ;
char ch = getchar();
while (ch < '' || ch > ''){
if (ch == '-')
f = -;
ch = getchar();
}
while (ch >= '' && ch <= ''){
x = x * + ch - '';
ch = getchar();
}
return x * f;
}
int n,m;
int dis[][];
int s,b;
ll kk,hh;
struct ship{
int x;
ll f;
ll a;
}ships[];
struct ene{
int x;
ll d;
}enes[];
int uN,vN;
int g[][];
int linker[];
int used[];
bool dfs(int u){
for(int v = ;v < vN;v++){
if(g[u][v] && !used[v]){
used[v] = true;
if(linker[v]==-||dfs(linker[v])){
linker[v]=u;
return true;
}
}
}
return false;
}
int hungary(){
int res = ;
memset(linker,-, sizeof(linker));
for(int u = ;u < uN;u++){
memset(used,false, sizeof(used));
if(dfs(u))res++;
}
return res;
}
int main(){
n=read();
m=read();
int u,v;
fo(i,,n){
fo(j,,n){
dis[i][j]=1e7;
}
dis[i][i]=;
}
fo(i,,m){
u=read();
v=read();
dis[u][v] = ;
}
fo(k,,n){
fo(i,,n){
fo(j,,n){
if(k==i||k==j||i==j)continue;
dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
}
}
}
s=read();b=read();kk=read();hh=read();
fo(i,,s){
ships[i].x=read();
ships[i].a=read();
ships[i].f=read();
}
fo(i,,b){
enes[i].x=read();
enes[i].d=read();
}
uN=s;
vN=b;
fo(i,,s){
fo(j,,b){
if(ships[i].a >= enes[j].d && dis[ships[i].x][ships[j].x] <= ships[i].f) g[i-][j-]=;
}
}
ll ans = min((ll)s*hh,kk*hungary());
cout<<ans;
return ;
}

C1

给若干个在长方形边上的点和一个不在边上的点,找出那个长方形

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include <map>
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define ll long long
using namespace std;
const int maxn = ;
const ll mod = 1e9+;
inline ll read(){
ll x = , f = ;
char ch = getchar();
while (ch < '' || ch > ''){
if (ch == '-')
f = -;
ch = getchar();
}
while (ch >= '' && ch <= ''){
x = x * + ch - '';
ch = getchar();
}
return x * f;
}
int n;
int x[maxn],y[maxn];
bool check(int x1,int x2,int y1,int y2){
int cnt = ,t=;
bool debug=false;
if(x1==&&x2==&&y1==&&y2==)debug=true;
fo(i,,n){
if(x[i]<x1||x[i]>x2||y[i]<y1||y[i]>y2){
cnt++;
t=i;
}else if(x[i]!=x1&&x[i]!=x2&&y[i]!=y1&&y[i]!=y2){
cnt++;
t=i;
}
if(cnt>)return false;
}
if(cnt == ) return false;
cout<<x[t]<<" "<<y[t];
return true;
}
int main(){
n=read();
n = n*+;
fo(i,,n){
x[i]=read();
y[i]=read();
}
fo(i,,){
fo(j,i,){
fo(k,,){
fo(l,k,){
if(check(i,j,k,l)) return ;
}
}
}
}
return ;
}

D1

一个长度n的线段和一个特殊点,每次插入或者切掉头或尾一段,每次询问特殊点的位置。

维护即可。

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include <map>
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define ll long long
using namespace std;
const int maxn = ;
const ll mod = 1e9+;
inline ll read(){
ll x = , f = ;
char ch = getchar();
while (ch < '' || ch > ''){
if (ch == '-')
f = -;
ch = getchar();
}
while (ch >= '' && ch <= ''){
x = x * + ch - '';
ch = getchar();
}
return x * f;
}
int n,k,m,t;
int main(){
n=read();k=read();
m=read();t=read();
int opt,v;
fo(i,,t){
opt=read();
v=read();
if(opt==){
n++;
if(v<=k)k++;
}else{
if(k > v){
n-=v;
k-=v;
}else{
n=v;
}
}
cout<<n<<" "<<k<<endl;
}
return ;
}

E1

给一个图,求出最小生成树,问如果第一条边可能在最小生成树里,其边权最多是多大

看看什么时候这条边对应的两个点处于同一个集合中。

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include <map>
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define ll long long
using namespace std;
const int maxn = ;
const ll mod = 1e9+;
inline ll read(){
ll x = , f = ;
char ch = getchar();
while (ch < '' || ch > ''){
if (ch == '-')
f = -;
ch = getchar();
}
while (ch >= '' && ch <= ''){
x = x * + ch - '';
ch = getchar();
}
return x * f;
}
int n,m;
int f[maxn];
int findf(int x){
return f[x]==x?x:f[x]=findf(f[x]);
}
struct edge{
int u;
int v;
ll w;
friend bool operator < (edge a,edge b){
return a.w < b.w;
}
}e[maxn*];
int main(){
n=read();m=read();
fo(i,,m){
e[i].u=read();
e[i].v=read();
e[i].w=read();
}
fo(i,,n){
f[i]=i;
}
int aa = e[].u,bb=e[].v;
sort(e+,e++m);
fo(i,,m){
int u=e[i].u;
int v=e[i].v;
int fu=findf(u),fv=findf(v);
if(fu==fv) continue;
if(e[i].u==aa&&e[i].v==bb)continue;
f[fu]=fv;
if(findf(aa)==findf(bb)){
 
cout<<e[i].w;
return ;
}
}
cout<<;
return ;
}

E2

与上一个问题类似,但是这次要求除了最小生成树的边之外所有边的答案

先求最小生成树,两个点之间加一条边,则形成一个环,由这条边和两者的树上最短路径的边组成,用lca求最短路径上的边的最大边权即可。

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include <map>
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define ll long long
using namespace std;
const int maxn = ;
const ll mod = 1e9+;
inline ll read(){
ll x = , f = ;
char ch = getchar();
while (ch < '' || ch > ''){
if (ch == '-')
f = -;
ch = getchar();
}
while (ch >= '' && ch <= ''){
x = x * + ch - '';
ch = getchar();
}
return x * f;
}
int n,m;
int f[maxn];
int findf(int x){
return f[x]==x?x:f[x]=findf(f[x]);
}
struct edge{
int u;
int v;
ll w;
int id;
friend bool operator < (edge a,edge b){
return a.w < b.w;
}
}e[maxn*];
bool chs[maxn*];
bool cmp(edge a,edge b){
return a.id < b.id;
}
int dep[maxn];
int fa[maxn][];
ll fw[maxn][];
struct te{
int v;
ll w;
}now,nxt;
vector<te> g[maxn];
void dfs(int x,int p){
int k = ;
while(fa[x][k]&&fa[fa[x][k]][k]){
fa[x][k+] = fa[fa[x][k]][k];
fw[x][k+] = max(fw[x][k],fw[fa[x][k]][k]);
k++;
}
int sz = g[x].size();
int v=;
fo(i,,sz-){
v=g[x][i].v;
if(v==p)continue;
fa[v][] = x;
fw[v][] = g[x][i].w;
dep[v] = dep[x] + ;
dfs(v,x);
}
}
ll getans(int u,int v){
if(dep[u]<dep[v]) swap(u,v);
ll mx = ;
int k = ,dif=dep[u]-dep[v];
int ru=u,rv=v;
while(dif){
if(dif&){
mx = max(fw[u][k],mx);
u = fa[u][k];
}
dif >>= ;
k++;
}
if(u==v)return mx;
k = ;
while(k >= ){
if(fa[u][k] != fa[v][k]){
mx = max(mx,fw[u][k]);
mx = max(mx,fw[v][k]);
u = fa[u][k];
v = fa[v][k];
k++;
}else{
k--;
}
}
mx = max(mx,fw[u][]);
mx = max(mx,fw[v][]);
return mx;
}
int main(){
n=read();m=read();
fo(i,,m){
e[i].u=read();
e[i].v=read();
e[i].w=read();
e[i].id=i;
}
fo(i,,n){
f[i]=i;
}
sort(e+,e++m);
fo(i,,m){
int u=e[i].u;
int v=e[i].v;
int fu=findf(u),fv=findf(v);
if(fu==fv) continue;
f[fu]=fv;
chs[e[i].id]=true;
now.w=e[i].w;
now.v=v;
g[u].push_back(now);
now.v=u;
g[v].push_back(now);
}
dfs(,);
sort(e+,e++m,cmp);
fo(i,,m){
if(chs[i])continue;
printf("%I64d\n",getans(e[i].u,e[i].v));
}
return ;
}

Helvetic Coding Contest 2019 online mirror (teams allowed, unrated)的更多相关文章

  1. Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)

    G. Fake News (easy) time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Helvetic Coding Contest 2017 online mirror (teams allowed, unrated) J

    Description Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their comm ...

  3. Helvetic Coding Contest 2017 online mirror (teams allowed, unrated) M

    Description The marmots have prepared a very easy problem for this year's HC2 – this one. It involve ...

  4. Helvetic Coding Contest 2017 online mirror (teams allowed, unrated) A

    Description Your search for Heidi is over – you finally found her at a library, dressed up as a huma ...

  5. Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)F3 - Lightsabers (hard)

    题意:n个数字1-m,问取k个组成的set方案数 题解:假设某个数出现k次,那么生成函数为\(1+x+...+x^k\),那么假设第i个数出现ai次,结果就是\(\sum_{i=1}^m(1+x+.. ...

  6. CF 690C3. Brain Network (hard) from Helvetic Coding Contest 2016 online mirror (teams, unrated)

    题目描述 Brain Network (hard) 这个问题就是给出一个不断加边的树,保证每一次加边之后都只有一个连通块(每一次连的点都是之前出现过的),问每一次加边之后树的直径. 算法 每一次增加一 ...

  7. Helvetic Coding Contest 2019 差A3 C3 D2 X1 X2

    Helvetic Coding Contest 2019 A2 题意:给一个长度为 n 的01序列 y.认为 k 合法当且仅当存在一个长度为 n 的01序列 x,使得 x 异或 x 循环右移 k 位的 ...

  8. [Helvetic Coding Contest 2017 online mirror]

    来自FallDream的博客,未经允许,请勿转载,谢谢, 第一次在cf上打acm...和同校大佬组队打 总共15题,比较鬼畜,最后勉强过了10题. AB一样的题目,不同数据范围,一起讲吧 你有一个背包 ...

  9. 【Codeforces】Helvetic Coding Contest 2017 online mirror比赛记

    第一次打ACM赛制的团队赛,感觉还行: 好吧主要是切水题: 开场先挑着做五道EASY,他们分给我D题,woc什么玩意,还泊松分布,我连题都读不懂好吗! 果断弃掉了,换了M和J,然后切掉了,看N题: l ...

随机推荐

  1. Python中函数传递参数有四种形式

    Python中函数传递参数有四种形式 fun1(a,b,c) fun2(a=1,b=2,c=3) fun3(*args) fun4(**kargs) 四种中最常见是前两种,基本上一般点的教程都会涉及, ...

  2. SpringMVC+Spring4+Mybatis3

    http://blog.csdn.net/jiuqiyuliang/article/details/45286191 http://blog.csdn.net/jiuqiyuliang/article ...

  3. pandas读取Excel文件

    In [7]: import pandas as pd filname = 'ch02数据导入\\student.xlsx' data = pd.read_excel(filname) data Ou ...

  4. Bash数组-判断某个元素是否在数组内的几种方法

    声明一个数组array,一个待测试元素var array=( element1 element2 element3 ) var="element1" 接下来用几种方法来分别测试va ...

  5. AtCoder Regular Contest 092 2D Plane 2N Points AtCoder - 3942 (匈牙利算法)

    Problem Statement On a two-dimensional plane, there are N red points and N blue points. The coordina ...

  6. blazeFace

    围绕四个点构造模型 1.扩大感受野 使用5*5卷积替换3*3来扩大感受野,在深度分离卷积中,pw与dw计算比为d/k^2,d为输出通道,k为 dw的卷积核,即增加dw的卷积核所带来的计算并不大. 在M ...

  7. mybatis返回自增主键问题踩坑

    1 <insert id="insert" keyProperty="id" useGeneratedKeys="true"
 par ...

  8. 【串线篇】spring boot整合SpringData JPA

    一.SpringData简介 其中SpringData JPA底层基于hibernate 二.整合SpringData JPA JPA: Java Persistence API的简称,中文名Java ...

  9. 谷歌将用QUIC传输层技术加速互联网

    安全这个话题,要感谢斯诺登,过去的安全就是攻和防之间的关系,即我们用一种什么样的体系.架构和模式去构建一个密不可破的安全系统.” 对IETF工作组忽视外部观察者看起来是一件甚么微不足道的事情的能力感到 ...

  10. vue-cli3.0以上项目中引入jquery的方法

    这里配置的是vue-cli3.0引入jquery的方法,不是vue-cli2.0的配置方法 一.安装jquery npm install jquery --save 二.在vue.config.js ...