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. 四、JVM — 类文件结构

    类文件结构 一 概述 二 Class 文件结构总结 2.1 魔数 2.2 Class 文件版本 2.3 常量池 2.4 访问标志 2.5 当前类索引,父类索引与接口索引集合 2.6 字段表集合 2.7 ...

  2. HDU 2196 Computer( 树上节点的最远距离 )

    Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  3. P3190 [HNOI2007]神奇游乐园

    传送门 第一道插头 $dp$ 由于讲不清楚所以假装各位早就会插头 $dp$ 了 首先要的是一个闭合回路,所以可以用括号表示法表示状态,然后大力分类讨论 $1.$ 没有右插头和下插头 那么我们可以啥也不 ...

  4. P1397 [NOI2013]矩阵游戏(递推)

    P1397 [NOI2013]矩阵游戏 一波化式子,$f[1][m]=a^{m-1}+b\sum_{i=0}^{m-2}a^i$,用快速幂+逆元求等比数列可以做到$logm$ 设$v=a^{m-1}, ...

  5. 【转】Hadoop 1.x中fsimage和edits合并实现

    在NameNode运行期间,HDFS的所有更新操作都是直接写到edits中,久而久之edits文件将会变得很大:虽然这对NameNode运行时候是没有什么影响的,但是我们知道当NameNode重启的时 ...

  6. Windows 环境下安装redis 及其PHP Redis扩展

    1.安装Redis (1)这里选择在github官网上下载Redis,地址:Redis下载地址 下载压缩包(如下图),并解压到本地目录,我放在D:\redis (2)验证Redis安装是否成功打开命令 ...

  7. java中关键字final,finally,finalize的区别

    -final:作为修饰符关键字,有三种用法: 1,如果一个类被声明为final,则意味着它不能被继承. 2,将变量声明为final,则表示它是一个常量,也就是保证它在使用过程中不被修改,被final修 ...

  8. 3.css3中多个背景图片的用法

    (background-clip裁剪,background-position位置,background-origin定位,background-repeat是否重复) <!DOCTYPE htm ...

  9. 理解长短期记忆网络(LSTM NetWorks)

    转自:http://www.csdn.net/article/2015-11-25/2826323 原文链接:Understanding LSTM Networks(译者/刘翔宇 审校/赵屹华 责编/ ...

  10. 七、ARM 指令集

    7.1 数据处理指令 7.1.1 数据传送类 MOV 类指令:核内寄存器间的数据传送 加载和存储指令(L/S):核内寄存器与挂在存储器总线上器件的数据传送 注意: 核内寄存器就是 R0-R15 外设寄 ...