csa Round #70
Digit Holes
Memory limit: 256 MB
When writing digits, some of them are considered to have holes: 00, 66 and 99 have one hole, while 88 has two holes. The other digits don't have any holes.
Given two integers AA and BB, find a value in the interval [A, B][A,B] that has the maximum total number of holes in its digits. If the solution is not unique, print the smallest one.
Standard input
The first line contains two integers AA and BB.
Standard output
Print the answer on the first line.
Constraints and notes
- 0 \leq A \leq B \leq 10000≤A≤B≤1000
| Input | Output | Explanation |
|---|---|---|
0 20 |
8 |
88 is the first integer in [0, 20][0,20] with 22 holes. |
10 20 |
18 |
1818 is the only integer in [10, 20][10,20] with 22 holes. |
1 100 |
88 |
8888 is the only integer in [1, 100][1,100] with 44 holes. |
统计每一位的贡献,直接取就行了,我本来还想去sort,那样麻烦了蛮多
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
vector<pii>A;
int la(int t)
{
int ans=;
if(!t)ans=;
while(t)
{
if(t%==||t%==||t%==)
ans+=;
else if(t%==)
ans+=;
t/=;
}
return ans;
}
int main()
{
int a,b;
cin>>a>>b;
int ma=a,maf=;
for(int i=a; i<=b; i++)
if(la(i)>maf)
{
ma=i;
maf=la(i);
}
cout<<ma;
return ;
}
Right Down Path
Memory limit: 256 MB
You are given a binary matrix AA of size N \times MN×M. You should find a path that starts in a cell, then goes to the right at least one cell, then goes down at least one other cell. That path should contain only cells equal to 11.
Find the longest path respecting these constraints.
Standard input
The first line contains two integers NN and MM.
Each of the next NN lines contains MM integers, 00 or 11, representing the elements of matrix AA.
Standard output
Print the size of the longest path on the first line.
Constraints and notes
- 2 \leq N, M \leq 3002≤N,M≤300
- It is guaranteed there is always at least one valid path
| Input | Output | Explanation |
|---|---|---|
4 4 |
4 |
One of the solutions of length 44 is bolded below. 0\ \bold{1}\ \bold{1}\ 00 1 1 0 1\ 1\ \bold{1}\ 01 1 1 0 1\ 0\ \bold{1}\ 01 0 1 0 1\ 1\ 0\ 01 1 0 0 |
5 4 |
5 |
The solutions of length 55 is bolded below. 1\ 0\ 1\ 01 0 1 0 \bold{1}\ \bold{1}\ \bold{1}\ 11 1 1 1 1\ 0\ \bold{1}\ 01 0 1 0 1\ 0\ \bold{1}\ 11 0 1 1 0\ 0\ 0\ 10 0 0 1 |
5 5 |
4 |
Note that you need to move at least once right and down. Because of this, the solutions consisting of the 5 ones on the sides is not valid. The valid solution is bolded below. 0\ 0\ 0\ 0\ 10 0 0 0 1 1\ 1\ 0\ 0\ 11 1 0 0 1 0\ 1\ 0\ \bold{1}\ \bold{1}0 1 0 1 1 0\ 0\ 0\ 0\ \bold{1}0 0 0 0 1 1\ 1\ 1\ 1\ \bold{1}1 1 1 1 1 |
从一个点开始可以向右然后向下,但是必须要走一格的,所以暴力的时候要判断有没有路
n^3的暴力
#include<bits/stdc++.h>
using namespace std;
int a[][];
int main()
{
int n,m,ans=;
cin>>n>>m;
for(int i=; i<n; i++)
for(int j=; j<m; j++)
cin>>a[i][j];
for(int i=; i<n-; i++)
for(int j=,k; j<m-; j++)
{
if(a[i][j])
{
for(k=j+; k<m; k++)
{
if(a[i][k])
{
if(a[i+][k])
{
int t=k-j+;
for(int l=i+;l<n;l++)
if(a[l][k])t++;
else break;
ans=max(ans,t);
}
}
else break;
}
j=k;
}
}
cout<<ans;
return ;
}
但是我当时写的是用后缀和和优化的,其实完全没有必要
#include<bits/stdc++.h>
using namespace std;
int a[][],s[][];
int main()
{
int n,m,ans=;
cin>>n>>m;
for(int i=; i<n; i++)
for(int j=; j<m; j++)
cin>>a[i][j];
for(int i=n-; i>=; i--)
for(int j=; j<m; j++)
if(a[i][j])s[i][j]=s[i+][j]+;
for(int i=; i<n; i++)
for(int j=; j<m; j++)
{
if(a[i][j])
for(int k=j; k<m; k++)
{
if(a[i][k])ans=max(ans,k-j+s[i][k]);
else break;
}
}
cout<<ans;
return ;
}
Min Distances
Memory limit: 256 MB
You should build a simple, connected, undirected, weighted graph with NN nodes. You are given MM constraints of the type a, b, ca,b,c, representing the fact that the minimum distance between nodes aa and bb should be cc.
Standard input
The first line contains two integers NN and MM.
Each of the next MM lines contains three integers aa, bb and cc representing a constraint.
Standard output
If there is no solution output -1−1.
Otherwise, print the number of edges your graph has on the first line.
Each of the next line should contain three integers aa, bb, ww, representing an edge (a, b)(a,b)with weight ww.
Constraints and notes
- 2 \leq N \leq 1002≤N≤100
- 0 \leq M \leq \binom{N}{2}0≤M≤(2N)
- 1 \leq a, b \leq N1≤a,b≤N and a \neq ba≠b
- 1 \leq c \leq 10^61≤c≤106
- The weigths ww should respect 1 \leq w \leq 10^71≤w≤107
| Input | Output | Explanation |
|---|---|---|
3 3 |
2 |
Note that the graph is not unique 12123 |
5 4 |
6 |
Note that the graph is not unique 23242112354 |
3 3 |
-1 |
There's no graph to satisfy all 3 restrictions. |


给定n个点M条边的最短路,让你构造一个图满足这个
因为是多源最短路,点数也不多,所以直接Floyd走一波然后判断是否合法
因为是无向图所以直接输出一半就好了
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
int M[][];
struct T
{
int a,b,c;
} t;
vector<T>V;
int main()
{
memset(M,INF,sizeof M);
int n,m;
cin>>n>>m;
for(int i=; i<m; i++)
cin>>t.a>>t.b>>t.c,V.push_back(t),M[t.a][t.b]=t.c,M[t.b][t.a]=t.c;
for(int k=; k<=n; k++)
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
M[i][j]=min(M[i][j],M[i][k]+M[k][j]);
int f=;
for(int i=; i<m&&f; i++)
{
t=V[i];
if(M[t.a][t.b]!=t.c)f=;
}
if(!f)printf("-1");
else
{
printf("%d\n",n*(n-)/);
for(int i=; i<=n; i++)
for(int j=i+; j<=n; j++)
if(M[i][j]!=INF)
printf("%d %d %d\n",i,j,M[i][j]);
else printf("%d %d %d\n",i,j,(int)1e7);
}
return ;
}
Distribute Candies
Memory limit: 256 MB
You should distribute NN candies in KK boxes such that the difference between the maximum and the minimum number of candies in a box is minimized. In addition, every pair of consecutive boxes should have a different number of candies.
Standard input
The first line contains two integers NN and KK.
Standard output
If there is no solution output -1−1.
Otherwise, print KK numbers on the first line, representing the number of candies in each box.
Constraints and notes
- 1 \leq N \leq 10^{18}1≤N≤1018
- 1 \leq K \leq 10^51≤K≤105
- Each box has to have a strictly positive amount of candies
- If the solution is not unique you can print any of them
| Input | Output |
|---|---|
15 2 |
8 7 |
16 4 |
3 5 3 5 |
100 80 |
-1 |
把n个盒子放进和为m的盒子里,且相邻盒子放的数不一样
取中间值,然后去构造就行了,奇偶分析
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
typedef long long ll;
ll n,m,a[N];
int main()
{
cin>>m>>n;
if(n==)cout<<m;
else
{
m-=n;
if(m<n/)cout<<-;
else
{
ll k=m%n;
if(k<(n/))k+=n;
m-=k,m+=n,m/=n;
for(int i=; i<n; i++)a[i]=m;
if(k==(n/))
{
for(int i=; i<n; i+=)a[i]++;
}
else if(k==((n+)/))
{
for(int i=; i<n; i+=)a[i]++;
}
else
{
for(int i=; i<n; i+=)a[i]++,k--;
for(int i=; k>&&i<n; i+=)a[i]++,k--;
for(int i=; k>&&i<n; i+=)a[i]++,k--;
}
for(int i=; i<n; i++)cout<<a[i]<<" ";
}
}
return ;
}
Squared Ends
Memory limit: 256 MB
You are given an array AA of NN integers. The cost of a subarray [A_l, A_{l+1},...A_r][Al,Al+1,...Ar]is equal to (A_l -A_r)^2(Al−Ar)2. Partition the array in KK subarrays having a minimum total cost.
Standard input
The first line contains two integers NN and KK.
The second line contains NN integers representing the elements of AA.
Standard output
Print the minimum total cost on the first line.
Constraints and notes
- 1 \leq N \leq 10^41≤N≤104
- 1 \leq K \leq min(N, 100)1≤K≤min(N,100)
- 1 \leq A_i \leq 10^61≤Ai≤106
| Input | Output | Explanation |
|---|---|---|
5 1 |
16 |
The only partition is [1, 5][1,5] with cost (5 - 1)^2 = 16(5−1)2=16 |
4 2 |
1 |
The partitions is [1, 3][1,3] and [4, 4][4,4] |
11 3 |
5 |
The 33 partitions are [2\ 4\ 1]\ [5\ 3\ 4\ 3\ 5\ 7]\ [100\ 100][2 4 1] [5 3 4 3 5 7] [100 100] |
动态凸包
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(int i=a;i<b;i++)
const ll is_query = -(1LL<<);
struct convex_line
{
ll m,b;
mutable function<const convex_line*()> succ;
bool operator<(const convex_line& rhs) const
{
if(rhs.b!=is_query) return m < rhs.m;
const convex_line* s=succ();
if(s==NULL) return ;
ll x=rhs.m;
return 1.0*(b-s->b)<1.0*(s->m-m)*x;
}
};
struct dcht : public multiset<convex_line>
{
bool invalid(iterator y)
{
auto z=next(y);
if(y==begin())
{
if (z==end()) return ;
return y->m==z->m && y->b<=z->b;
}
auto x=prev(y);
if(z==end()) return y->m==x->m && y->b<=x->b;
return 1.0*(x->b-y->b)*(z->m-y->m)>=1.0*(y->b-z->b)*(y->m-x->m);
} void insert_line(ll m,ll b) //insert any line
{
auto y = insert({m,b});
y->succ = [=] { return next(y) == end() ? : &*next(y); };
if (invalid(y))
{
erase(y);
return;
}
while (next(y) != end() && invalid(next(y))) erase(next(y));
while (y != begin() && invalid(prev(y))) erase(prev(y));
} void remove_line(ll m,ll b)
{
auto y=find({m,b});
if(y==end()) return;
erase(y);
} ll eval(ll x)
{
auto l=lower_bound({x, is_query});
return (*l).m * x + (*l).b;
}
};
const int N=;
const ll inf=(ll)1e18;
ll a[N];
ll dp[][N];
int main()
{
std::ios::sync_with_stdio(false);
int n,k;
cin>>n>>k;
rep(i,,n+) cin>>a[i];
rep(i,,) rep(j,,N) dp[i][j]=inf;
dp[][]=;
rep(j,,k+)
{
dcht cht;
cht.insert_line(*a[],-dp[j-][]-(a[]*a[]));
rep(i,,n+)
{
dp[j][i]=a[i]*a[i]-cht.eval(a[i]);
cht.insert_line(*a[i+],-dp[j-][i]-(a[i+]*a[i+]));
}
}
cout<<dp[k][n]<<endl;
return ;
}
这份代码也不错
csa Round #70的更多相关文章
- CSA Round #54 $\ $Voting
CSA Round #54 \(\ \)Voting 题目大意: 原题网址:戳我戳我! 一次歌唱比赛中,一位歌手刚刚结束表演,评委正在打分. 一共有 \(n\) 位评委,他们每人可以打 \(1\) 分 ...
- Codeforces Beta Round #70 (Div. 2)
Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...
- 水题 Codeforces Beta Round #70 (Div. 2) A. Haiku
题目传送门 /* 水题:三个字符串判断每个是否有相应的元音字母,YES/NO 下午网速巨慢:( */ #include <cstdio> #include <cstring> ...
- 题解-CSA Round#18 Randomly Permuted Costs
Problem CSA Round 18 题意概要:给定一个有重边有自环 \(n\) 点 \(m\) 边的有向无环图(DAG),每条边有其权值,每当你走到一个点 \(x\) 时,所有从 \(x\) 连 ...
- 【题解】Comet OJ Round 70 简要题解
[题解]Comet OJ Round 70 简要题解 A 将放在地上的书按照从小到大排序后,问题的本质就变成了合并两个序列使得字典序最小.可以直接模拟归并排序.直接用循环和std::merge实现这个 ...
- Contest Hunter Round #70 - 连续两大交易事件杯省选模拟赛
orz lydrainbowcat [Problem A]「艦これ市」70万幕后交易事件 排序机器=-=.重要的是相同的处理. 我们可以从小到大添加数字,然后维护一个位置的序列.每一种相等的数字都在一 ...
- BestCoder Round 70
惨败,不能再嘲笑别人了,否则自己也会像别人那样倒霉 HDU 5615:http://acm.hdu.edu.cn/showproblem.php?pid=5615 求ax^2+bx+c能否拆成(px+ ...
- BestCoder Round #70 Jam's math problem(hdu 5615)
Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ...
- HDU 5618 Jam's problem again CDQ分治 BC ROUND 70
题意:给你1e5个点(x,y,z),对于每一个点询问有多少个点(x1,y1,z1)满足x1<=x&&y1<=y&&z1<=z 分析:(官方题解奉上)很 ...
随机推荐
- GetRelativePath获取相对路径
public static string GetRelativePath(string baseDirPath, string subFullPath) { // ForceBasePath to a ...
- UI设计中蕴涵着系统重要的数据结构与功能设计
UI设计中蕴涵着系统重要的数据结构与功能设计 UI设计中的用户需求,事件(用例)驱动
- LINQ 基础语句
去全部集合 using (dat0216DataContext con = new dat0216DataContext()) { //LoList 是转换成 List集合 List<Us ...
- HDU 1864 最大报销额(01背包,烂题)
题意:被坑惨,单项不能超过600,其实是一张发票上A类/B类/C类的总和分别不能超过600. 思路:此题的数据很烂.用贪心也能过,用01背包也可以.都测试不出到底那些是错的. #include < ...
- lca(最近公共祖先(在线)) 倍增法详解
转自大佬博客 : https://blog.csdn.net/lw277232240/article/details/72870644 描述:倍增法用于很多算法当中,通过字面意思来理解 LCA是啥呢 ...
- Bootstrap历练实例:下拉菜单插件方法的使用
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- Java第11次作业:什么是继承?继承的好处?什么是覆写?super()?构造代码块?子父类初始化顺序? 抽象类能用final声明吗?final关键字声明类 方法 变量以及全局常量?抽象类的构造方法?
什么是继承? 继承是以父类为基础,子类可以增加新的数据或新的功能.子类不能选择性地继承父类.这种技术使得复用以前的代码非常容易. JAVA不支持多继承,单继承使JAVA的继承关系很简单,一个类只能有一 ...
- iOS动画之iOS UIBezierPath类 介绍
感谢:http://blog.csdn.net/crayondeng/article/details/11093689 使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中.此类 ...
- Voyager的安装及配置文件
使用代理服务器安装laravel http_proxy=http://localhost:1080 composer create-project --prefer-dist laravel/lara ...
- MySQL创建根据经纬度计算距离的函数
按照经纬度计算距离 日常开发中,特别是做微信项目时,经常会遇到根据用户地理位置来展示附近商家的功能,通常解决这种问题的思路是,后台设置商家的经纬度,然后再根据前台传的经纬度进行计算,具体经纬度转换以及 ...