Helvetic Coding Contest 2019 online mirror (teams allowed, unrated)
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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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+.. ...
- CF 690C3. Brain Network (hard) from Helvetic Coding Contest 2016 online mirror (teams, unrated)
题目描述 Brain Network (hard) 这个问题就是给出一个不断加边的树,保证每一次加边之后都只有一个连通块(每一次连的点都是之前出现过的),问每一次加边之后树的直径. 算法 每一次增加一 ...
- Helvetic Coding Contest 2019 差A3 C3 D2 X1 X2
Helvetic Coding Contest 2019 A2 题意:给一个长度为 n 的01序列 y.认为 k 合法当且仅当存在一个长度为 n 的01序列 x,使得 x 异或 x 循环右移 k 位的 ...
- [Helvetic Coding Contest 2017 online mirror]
来自FallDream的博客,未经允许,请勿转载,谢谢, 第一次在cf上打acm...和同校大佬组队打 总共15题,比较鬼畜,最后勉强过了10题. AB一样的题目,不同数据范围,一起讲吧 你有一个背包 ...
- 【Codeforces】Helvetic Coding Contest 2017 online mirror比赛记
第一次打ACM赛制的团队赛,感觉还行: 好吧主要是切水题: 开场先挑着做五道EASY,他们分给我D题,woc什么玩意,还泊松分布,我连题都读不懂好吗! 果断弃掉了,换了M和J,然后切掉了,看N题: l ...
随机推荐
- Django、Flask、Tornado的区别?
Django:Python 界最全能的 web 开发框架,battery-include 各种功能完备,可维护性和开发速度一级棒.常有人说 Django 慢,其实主要慢在 Django ORM 与数据 ...
- C++关于erase的复杂度(转载)
被这个问题困扰了很多次,有必要整理一下. 当然最好的参考资料就是http://www.cplusplus.com/reference/set/set/erase/ 里的Complexcity部分了,但 ...
- Datatable 中的数据查询(查询不重复记录)
http://blog.csdn.net/lovexiaoxiao/article/details/3734932 //在sql中我们使用distinct查询不重复记录 //然而我在项目中表关系 ...
- 浏览器常用12种兼容问题(JS)
//1.滚动条到顶端的距离(滚动高度) var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; / ...
- 6.css3定位--position
⑴Static默认值,没有定位. ⑵Absolute绝对定位.后面的元素会补上原来偏移的位置. ⑶Relative相对定位.后面的元素不会补上原来偏移的位置. ⑷Fixed绝对定位.相对于浏览器窗口固 ...
- Hive常用数据库操作
1.创建表的三种姿势 第一种 //员工表 create table if not exists default.emp( empno int, ename string, job string, mg ...
- 计算视图相对坐标时convertPoint:toView: ,UIApplication sharedApplication - keyWindow is nil?
UIWindow *window = [UIApplication sharedApplication].keyWindow; window 为nil的原因:在指定rootViewController ...
- Apache 配置外网站点
基于域名,一般是对外网站 www.etiantian.org/var/www/html/www blog.etiantian.org /var/www/html/blog bbs.tiantian.o ...
- python3:类和实例
面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板,比如Student类,而实例是根据类创建出来的一个个具体的“对象”,每个对象都拥有相同的方法,但各自的数据可 ...
- zookeeper之三 ZKClient客户端的使用
ZKClient在原生API接口上进行了包装,同时在内部实现了诸如session超时重连.watcher反复注册等功能,使得zookeeper客户端繁琐的细节对开发人员透明.下面将从以下几个方面来使用 ...