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. 关于使用iframe的父子页面进行简单的相互传值

    当一个页面使用了iframe作为嵌套时,如何想要将父页面的数据传给iframe子页面,那iframe所指向的呢个子页面是怎么获取呢,又或者子页面的数据要给父页面使用,那么父页面又如何获取子页面的数据呢 ...

  2. 关于BeanUtils.copyProperties的用法和优缺点

    一.简介:  BeanUtils提供对Java反射和自省API的包装.其主要目的是利用反射机制对JavaBean的属性进行处理.我们知道,一个JavaBean通常包含了大量的属性,很多情况下,对Jav ...

  3. git上传代码到code.csdn.net

    国内有code.csdn.net速度很快 用git上传需要去下载git程序 很简单. 我是Windows下 先code.csdn.net创建一个项目 https://code.csdn.net/das ...

  4. centOS7 通过nmtui和nmcli图形配置网络服务

    一.通过nmtui配置网络参数 Linux系统配置网络参数的方式有很多种,其中最简单最直接的方式就是直接修改网卡配置文件,但这种方式也很容易出错,比如说IPADDR.NETMASK.GATEWAY等参 ...

  5. PAT Advanced 1036 Boys vs Girls (25 分)

    This time you are asked to tell the difference between the lowest grade of all the male students and ...

  6. flutter 基础组件

    TextWidget class TextWidget extends StatelessWidget { final TextStyle _textStyle = TextStyle( fontSi ...

  7. 详解InitializingBean、initMethod和@PostConstruct

    转载:https://blog.csdn.net/nrsc272420199/article/details/95033223 1. InitializingBean.initMethod和@Post ...

  8. java Byte源码分析

    源码: public static int toUnsignedInt(byte x) { return ((int) x) & 0xff; } 原理: -128(byte) 原码:10000 ...

  9. java web 增加信息课堂测试00

    按照图片要求设计添加新课程界面.(0.5分)在后台数据库中建立相应的表结构存储课程信息.(0.5分)实现新课程添加的功能.要求判断任课教师为王建民.刘立嘉.刘丹.王辉.杨子光五位教师的其中一位.(0. ...

  10. ansible 基础操作

    ansible是什么? 可以批量在远程主机上执行命令 准备条件: 1.创建一台环境干净的虚拟机. 2.克隆出三台虚拟机. 3.安装wget: wget -O /etc/yum.repos.d/Cent ...