diverta 2019 Programming Contest 2

A - Ball Distribution

特判一下一个人的,否则是\(N - (K - 1) - 1\)

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,K;
void Solve() {
read(N);read(K);
if(K == 1) puts("0");
else {
out((N - (K - 1)) - 1);enter;
}
}
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

B - Picking Up

枚举p,q(就是枚举一个点对计算p和q),判哪一种情况最优即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
map<pii,int> zz;
pii poi[55];
void Solve() {
read(N);
int x,y;
for(int i = 1 ; i <= N ; ++i) {
read(poi[i].fi);read(poi[i].se);
zz[poi[i]] = 1;
}
int ans = N;
for(int i = 1 ; i <= N ; ++i) {
for(int j = 1 ; j <= N ; ++j) {
if(i == j) continue;
int p = poi[i].fi - poi[j].fi,q = poi[i].se - poi[j].se;
int tmp = N;
for(int h = 1 ; h <= N ; ++h) {
tmp -= zz[mp(poi[h].fi - p,poi[h].se - q)];
}
ans = min(ans,tmp);
}
}
out(ans);enter; }
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

C - Successive Subtraction

又有负数又有正数

先挑出一个正数一个负数,用这个负数减遍所有正数(除了挑出来的),再用这个正数减遍所有负数(包括挑出来的)

就可以获得所有数的绝对值和

只有正数

会牺牲一个最小的正数,方法是挑出最小的正数,再挑一个正数,用最小的正数减遍所有的正数(除了挑出来的),再用挑的正数减掉最小的正数当前的值

只有负数

会牺牲一个最小的负数,用这个负数减遍其余负数即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,a[100005],cnt[2];
vector<pii > ans;
int64 res = 0;
void Solve() {
read(N); for(int i = 1 ; i <= N ; ++i) {
read(a[i]);
if(a[i] < 0) cnt[0]++;
else cnt[1]++;
}
if(cnt[0] && cnt[1]) {
int s,t;
for(int i = 1 ; i <= N ; ++i) res += abs(a[i]);
for(int i = 1 ; i <= N ; ++i) {
if(a[i] >= 0) s = i;
if(a[i] < 0) t = i;
}
for(int i = 1 ; i <= N ; ++i) {
if(a[i] >= 0 && i != s) {
ans.pb(mp(a[t],a[i]));
a[t] -= a[i];
}
}
for(int i = 1 ; i <= N ; ++i) {
if(a[i] < 0) {
ans.pb(mp(a[s],a[i]));
a[s] -= a[i];
}
}
}
else if(cnt[0]) {
int p = 1;
for(int i = 2 ; i <= N ; ++i) {
if(a[i] > a[p]) p = i;
}
res += a[p];
for(int i = 1 ; i <= N ; ++i) {
if(i != p) res += abs(a[i]);
}
for(int i = 1 ; i <= N ; ++i) {
if(i != p) {
ans.pb(mp(a[p],a[i]));
a[p] -= a[i];
}
}
}
else {
int p = 1,q;
for(int i = 2 ; i <= N ; ++i) {
if(a[i] < a[p]) p = i;
}
res -= a[p];
for(int i = 1 ; i <= N ; ++i) {
if(i != p) res += a[i];
}
if(p == 1) q = 2;
else q = 1;
for(int i = 1 ; i <= N ; ++i) {
if(i != p && i != q) {
ans.pb(mp(a[p],a[i]));
a[p] -= a[i];
}
}
ans.pb(mp(a[q],a[p]));
}
out(res);enter;
for(auto t : ans) {
out(t.fi);space;out(t.se);enter;
}
}
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

D - Squirrel Merchant

设\(f[i]\)表示有\(i\)个松果最多可以换成几个,用金银铜做背包就好了

不过这个背包大小最多可以是2500000……

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int64 f[25000005],N;
int g[5][5];
void Solve() {
read(N);
for(int i = 0 ; i < 2 ; ++i) {
for(int j = 0 ; j < 3 ; ++j) {
read(g[i][j]);
}
}
for(int i = 1 ; i <= N ; ++i) f[i] = i;
for(int i = 0 ; i < 3 ; ++i) {
for(int s = g[0][i] ; s <= N ; ++s) {
f[s] = max(f[s],f[s - g[0][i]] + g[1][i]);
}
}
int all = f[N];
for(int i = 1 ; i <= all ; ++i) f[i] = i;
for(int i = 0 ; i < 3 ; ++i) {
for(int s = g[1][i] ; s <= all ; ++s) {
f[s] = max(f[s],f[s - g[1][i]] + g[0][i]);
}
}
out(f[all]);enter;
}
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

E - Balanced Piles

计数水平不行……

这个就是,从\(0,N\)表示最大值是0,有\(N\)个数

并且我们认为相同的值选择顺序被我们确定了

如果\(D = 1\)

那么从\(x,y\),转移\(x + 1,0\)的时候,系数为1

从\(x,y\)转移到\(x,y + 1\)的时候,系数为\(y + 1\),因为我们要计数这个特定的选择顺序,在\(y\)个数的排列里插上一个数,要乘上\(y + 1\)

显然我们开头的部分需要一个\(N!\),但是由于\(H\)的\(N!\)不必要但是被算了,所以需要\(\frac{1}{N!}\),那么两个抵消了,所以可以直接这样计数

我们把转移画成一张图,发现每层转移到下一层的方案数是

\((1! + 2! +3!+4!....N!)\)

然后有\(H\)层,那么方案数是(第一层的方案是1)

\((1! + 2!+3!+4!+5!....N!)^{H - 1}N!\)

那么回到原来的问题,如果我们最大值交替一共过了\(K\)个,那么方案数是

\((1! + 2!+3!+4!+5!....N!)^{K - 1}N!\)

所以我们只要做一个路径计数,每走一步乘一个\(1! + 2!+3!+4!+5!....N!\),最后乘上一个\(\frac{N}{1!+2!+3!+4!...N!}\)

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,H,D;
int fac[1000005],dp[1000006],sum[1000006];
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
void update(int &x,int y) {
x = inc(x,y);
}
int fpow(int x,int c) {
int res = 1,t = x;
while(c) {
if(c & 1) res = mul(res,t);
t = mul(t,t);
c >>= 1;
}
return res;
}
void Solve() {
read(N);read(H);read(D);
fac[0] = 1;
int c = 0;
for(int i = 1 ; i <= N ; ++i) {
fac[i] = mul(fac[i - 1],i);
update(c,fac[i]);
}
dp[0] = c;sum[0] = 1;
for(int i = 1 ; i <= H ; ++i) {
int t = sum[i - 1];
if(i - D > 0) update(t,MOD - sum[i - D - 1]);
dp[i] = mul(t,c);
sum[i] = inc(sum[i - 1],dp[i]);
}
int ans = mul(dp[H],fac[N]);ans = mul(ans,fpow(c,MOD - 2));
out(ans);enter;
}
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

F - Diverta City

水平不行,想不到

还是类似数学归纳法那么构造,假如构造了\(i\)个点的完全图使得所有哈密顿路径不同,我们找到哈密顿路径最大的那个是\(M\)

然后选择一个数列

1,2,4,7,12,20,29,38,53,73

设\(M\)为i个点中最长哈密顿路径最大的那个

新加一个点\(i +1\)的时候向\(j\)连一条长度为\((M + 1)a_{j}\)的边

这个数列任意两个数相加的值不同,且不等于其中任意一个数

这样每条路径经过了两条或一条这样的边,剩余的部分的边权不足以使得两个不同的\((M + 1)k\)相等

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
} int N,tot;
int64 w[15][15],M,a[] = {0,1,2,4,7,12,20,29,38,53,73};
bool vis[15];
void dfs(int dep,int pre,int64 sum) {
if(dep > tot) {
M = max(M,sum);
return;
}
for(int i = 1 ; i <= tot ; ++i) {
if(!vis[i]) {
vis[i] = 1;
dfs(dep + 1,i,sum + w[pre][i]);
vis[i] = 0;
}
}
}
void Solve() {
read(N);
M = 0;
for(int i = 2 ; i <= N ; ++i) {
for(int j = 1 ; j < i ; ++j) {
w[i][j] = w[j][i] = (M + 1) * a[j];
}
tot = i;
dfs(1,0,0);
}
for(int i = 1 ; i <= N ; ++i) {
for(int j = 1 ; j <= N ; ++j) {
out(w[i][j]);space;
}
enter;
}
}
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

【AtCoder】diverta 2019 Programming Contest 2的更多相关文章

  1. 【AtCoder】diverta 2019 Programming Contest

    diverta 2019 Programming Contest 因为评测机的缘故--它unrated了.. A - Consecutive Integers #include <bits/st ...

  2. AtCoder diverta 2019 Programming Contest 2

    AtCoder diverta 2019 Programming Contest 2 看起来我也不知道是一个啥比赛. 然后就写写题解QWQ. A - Ball Distribution 有\(n\)个 ...

  3. 【AtCoder】ExaWizards 2019

    ExaWizards 2019 C - Snuke the Wizard 发现符文的相对位置不变,直接二分某个位置是否到达最左或最右来计算 #include <bits/stdc++.h> ...

  4. diverta 2019 Programming Contest 2自闭记

    A 签到(a-b problem不用贴了吧,以后atcoder小于300分题均不贴代码) B 发现选择的p,q一定是其中两点间的距离,于是可以O(n2)枚举两点,再O(n2)判断,其实可以做到O(n3 ...

  5. diverta 2019 Programming Contest 2

    A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...

  6. diverta 2019 Programming Contest

    A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...

  7. 【题解】CF1056F Write the Contest(三分+贪心+DP)

    [题解]CF1056F Write the Contest(三分+贪心+DP) 最优化问题的三个解决方法都套在一个题里了,真牛逼 最优解应该是怎样的,一定存在一种最优解是先完成了耗时长的任务再干别的( ...

  8. 【AtCoder】M-SOLUTIONS Programming Contest

    M-SOLUTIONS Programming Contest A - Sum of Interior Angles #include <bits/stdc++.h> #define fi ...

  9. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

随机推荐

  1. 开源是个巨大的坑,谁来帮帮我 - smartmontools 虐我记

    最近在试用smartmontools,感觉还行,于是乎想找来源码改改试试,这下可好,掉坑里了.呜呜呜... smartmontools的源码在这里可以看到:https://www.smartmonto ...

  2. Mybatis 向statement传入多个参数

    1.一般情况下可以将多个参数放入Map,让Map作为statement的参数 public void update(@Param("fieldMap") Map<String ...

  3. selenium鼠标下滑操作

    # coding = utf-8 import time from selenium import webdriver from selenium.webdriver.common.by import ...

  4. WPF_AutoCompleteBox智能提示_Xml读写

    效果图 1.需要引用的DLL 2. Window.xaml <Window x:Class="自己的命名空间" xmlns="http://schemas.micr ...

  5. Jenkins 更新 jenkins.war的方法

    Jenkins 有时候更新,直接是主页提示下载 jenkins.war只需要把下载的jenkins.war 替换原来的jenkins.war 就可以了那么问题来了? 原来的 jenkins.war 到 ...

  6. Asis_2016_b00ks wp

    目录 程序基本信息 程序漏洞 利用思路 exp脚本 参考 程序基本信息 程序漏洞 有一个读入函数,程序的所有输入都靠它读取,这个程序有个很明显的off_by_one漏洞,在输入时多输入一个0字符. 利 ...

  7. libmidas.so.2

    libmidas.so.2 libmidas.so.2文件,使DATASNAP FOR LINUX中间件,支持OleVariant格式的序列,使TDataSetProvider+TClientData ...

  8. 基于python的人脸识别(检测人脸、眼睛、嘴巴、鼻子......)

    本文链接:https://blog.csdn.net/James_Ray_Murphy/article/details/79209172 import numpy as np import cv2 # ...

  9. $createElement实现自定义弹窗

    <el-button type="text" @click="open4">点击打开 Message Box</el-button> m ...

  10. insmod某个内核模块时提示“Failed to find the folder holding the modules”如何处理?

    答: 创建/lib/modules/$(uname -r)目录,命令如下: mkdir /lib/modules/$(uname -r)