B. Balanced Diet

思路:把每一块选C个产生的价值记录下来,然后从小到大枚举C。

 #include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
typedef long long ll;
vector<int> G[maxn];
int l[maxn], a[maxn], b[maxn];
ll dp[maxn];
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
int n, m;
cin >> n >> m;
for(int i = ;i <= m;i++){
cin >> l[i];
G[i].clear();
}
fill(dp, dp + + n, );
for(int i = ;i <= n;i++){
cin >> a[i] >> b[i];
G[b[i]].push_back(a[i]);
}
int cnt = ;
for(int i = ;i <= m;i++){
sort(G[i].begin(), G[i].end(),cmp);
if(G[i].size() < l[i]) continue;
ll k = ;
for(int j = ;j < G[i].size();j++){
if(j < l[i])
k += G[i][j];
else
dp[j + ] += G[i][j];
}
dp[l[i]] += k;
}
for(int i = ;i <= n;i++)dp[i] += dp[i-];
ll fz = ,fm = ;
for(int i = ;i <= n;i++){
long double pre = fz *1.0 / fm;
long double after = 1.0 * dp[i]/ i * 1.0;
if(after > pre) fz = dp[i] , fm = i;
}
ll d = __gcd(fz, fm);
fz /= d;
fm /= d;
cout << fz << "/" << fm << endl;
}
return ;
}

C. Line-line Intersection

思路:用map分别记录所有直线的斜率和于X轴的交点XC,如果斜率与交点都相同则直线重合,每条直线都与他斜率不同且不重合的直线有交点。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<pair<ll,ll>,ll> k ;
map<pair<pair<ll,ll>,ll>,ll> c;
int main()
{
std::ios::sync_with_stdio(false);
int t;
int n;
cin >> t;
while(t--)
{
cin >>n;
k.clear();
c.clear();
ll ans = ;
ll x1, x2, y1, y2, XC;
for(int i = ;i < n;i++)
{
cin >> x1 >> y1 >> x2 >> y2;
XC = x1 * y2 - x2 * y1;
ll x = x2 - x1;
ll y = y2 - y1;
ll d = __gcd(x, y);
x /= d;
y /= d;
XC /= d;
ans += i + c[{{x, y}, XC}] - k[{x, y}];
c[{{x, y}, XC}]++;
k[{x, y}]++;
}
cout << ans << endl;
}
return ;
}

E. Minimum Spanning Tree

思路:首先我们可以从每条边权(即每个点的出边)的贡献入手,首先一个点的出边必须连通,否则构不成最小生成树。

那么对于特定的一个点,首先将其所有出边全部的权值加一遍,然后将其最小的一个边权乘以(这一点的度degree-2)即保证了最优解当degree==1 时会把多加的ans减去,因此遍历所有点进行上述操作即可。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
const int INF = 0x3f3f3f3f;
struct node{
int to, cost;
bool operator <(const node &b)
{
return cost < b.cost;
}
};
vector<node> G[maxn];
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
int n;cin >> n;
for(int i = ;i <= n;i++) G[i].clear();
for(int i = ;i < n - ;i++)
{
int a, b, c;
cin >> a >> b >> c;
G[a].push_back(node{b, c});
G[b].push_back(node{a, c});
}
ll ans = ;
for(int i = ;i <= n;i++)
{
sort(G[i].begin(), G[i].end());
int minn = INF;
for(int j = ;j < G[i].size();j++){
ans += G[i][j].cost;
minn = min(minn,G[i][j].cost);
}
ans += (ll)minn*(G[i].size() - 2LL);
}
cout << ans << endl;
}
return ;
}

G. Radar Scanner

思路:题意可转化为求所有矩形移动到一个格点的最短距离,将x和y上的移动距离分开考虑,对于X轴,选一个位置,使它到所有格点的距离最小,这个X就是所有格点的中位数(不难证明),Y同理,因此可以求出那个格点(X,Y),最后一个个求一下移动到(X,Y)的距离即可。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + ;
ll x[maxn], y[maxn];
ll x1[maxn], x2[maxn], y1[maxn], y2[maxn];
int main()
{
std::ios::sync_with_stdio(false);
int n;
int t;
cin >> t;
while(t--)
{
cin >> n;
int cnt = ;
for(int i = ;i < n;i++)
{
cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
x[cnt] = x1[i];
y[cnt++] = y1[i];
x[cnt] = x2[i];
y[cnt++] = y2[i];
}
sort(x, x + cnt);
sort(y, y + cnt);
ll ans = ;
ll x0 = x[cnt / ], y0 = y[cnt / ];
for(int i = ;i < n;i++)
{
if(x1[i] > x0) ans += x1[i] - x0 ;
else if(x0 > x2[i])ans += x0 - x2[i];
if(y1[i] > y0) ans += y1[i] - y0 ;
else if(y0 > y2[i])ans += y0 - y2[i];
}
cout << ans << endl;
}
return ;
}

H. Skyscraper

思路:区间修改可以用差分实现,将整个数组转换成差分数组之后,就会发现所求的答案 [ l , r ] 就是a[l] + (b[l+1] ~ b[r])这段区间中非负的值的总和。a[l] = (b[1] + ... + b[l])

 #include<bits/stdc++.h>
using namespace std;
#define ls rt << 1
#define rs rt << 1 | 1
#define lr2 (l + r) >> 1
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int maxn = 1e5 + ;
ll a[maxn],b[maxn];//b是差分数组
ll val[maxn << ], sum[maxn << ];
void pushup(int rt)
{
sum[rt] = sum[ls] + sum[rs];
val[rt] = val[ls] + val[rs];
}
void build(int l, int r, int rt)
{
if(l == r){
val[rt] = b[l];
sum[rt] = b[l] > ? b[l] : ;
return;
}
int mid = lr2;
build(lson);
build(rson);
pushup(rt);
}
void update(int k, int v, int l, int r, int rt){
if(l == r){
val[rt] += v;
sum[rt] = val[rt] > ? val[rt] : ;
return;
}
int mid = lr2;
if(k <= mid) update(k, v, lson);
else update(k, v, rson);
pushup(rt);
}
ll queryval(int a, int b, int l, int r, int rt)
{
if(a > b)return ;
if(a <= l && b >= r){
return val[rt];
}
int mid = lr2;
ll ans = ;
if(a <= mid) ans += queryval(a, b, lson);
if(b > mid) ans += queryval(a, b, rson);
return ans;
}
ll querysum(int a, int b, int l, int r, int rt)
{
if( a <= l && b >= r){
return sum[rt];
}
ll ans = ;
int mid = lr2;
if(a <= mid) ans += querysum(a, b, lson);
if(b > mid) ans += querysum(a, b, rson);
return ans;
}
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
int n, m;
cin >> n >> m;
for(int i = ;i <= n;i++)
{
cin >> a[i];
b[i] = a[i] - a[i - ];
}
build( ,n, );
int l, r, k;
while(m--)
{
int c;
cin >> c;
if(c == ){
cin >> l >> r >> k;
update(l, k, , n, );
if(r < n)
update(r + , -k, , n, );
}
else{
cin >> l >> r;
cout << querysum(l + , r, , n, ) + queryval(, l, , n, ) << endl;
}
}
}
return ;
}

J. Time Limit

思路:x =max(3*a1, ai+1),若x是奇数再加1

 #include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
int a;
cin >> a;
int ans = * a;
for(int i = ;i < n;i++) cin >> a,ans = max(ans, a + );
if(ans & ) ans += ;
cout << ans << endl;
}
return ;
}

The 13th Chinese Northeast Collegiate Programming Contest(B C E F H J)的更多相关文章

  1. The 13th Chinese Northeast Collegiate Programming Contest

    题解: solution Code: A. Apple Business #include<cstdio> #include<algorithm> #include<ve ...

  2. 【The 13th Chinese Northeast Collegiate Programming Contest E题】

    题目大意:给定一棵 N 个点的树,边有边权,定义"线树"为一个图,其中图的顶点是原树中的边,原树中两条有公共端点的边对应在线图中存在一条边,边权为树中两条边的边权和,求线图的最小生 ...

  3. 【The 13th Chinese Northeast Collegiate Programming Contest H 题】

    题目大意:NOIP2018d1t1 支持 M 次区间查询答案和区间修改操作. 题解: 首先考虑不带区间修改的情况.从左到右进行考虑,发现对于第 i 个数来说,对答案的贡献仅仅取决于第 i-1 个数的大 ...

  4. ZOJ 3946.Highway Project(The 13th Zhejiang Provincial Collegiate Programming Contest.K) SPFA

    ZOJ Problem Set - 3946 Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the ...

  5. The 13th Zhejiang Provincial Collegiate Programming Contest - D

    The Lucky Week Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the headmaster of the Marja ...

  6. The 13th Zhejiang Provincial Collegiate Programming Contest - I

    People Counting Time Limit: 2 Seconds      Memory Limit: 65536 KB In a BG (dinner gathering) for ZJU ...

  7. The 13th Zhejiang Provincial Collegiate Programming Contest - C

    Defuse the Bomb Time Limit: 2 Seconds      Memory Limit: 65536 KB The bomb is about to explode! Plea ...

  8. The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - F 贪心+二分

    Heap Partition Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge A sequence S = { ...

  9. The 2018 ACM-ICPC Chinese Collegiate Programming Contest Moving On

    Firdaws and Fatinah are living in a country with nn cities, numbered from 11 to nn.Each city has a r ...

随机推荐

  1. [BZOJ3622] 已经没有什么好害怕的了(dp+容斥)

    Description: ​ 有两个数组a和b,两两配对,求 \(a_i>b_i\) 的配对比 \(b_i>a_i\) 的配对多 \(k\) 个的方案数 \(k\le n\le 2000\ ...

  2. 《剑指offer》面试题8 旋转数组的最小数字 Java版

    (找递增排序旋转数组中的最小数字) 书中方法:这种题目就是要寻找数组的特点,然后根据这个特点去写.旋转后的递增数组分为两段递增序列,我们找到中点,如果比第一个元素大,表示在第一段递增序列里,如果比第一 ...

  3. 解决mxGraph放大/缩小在非IE浏览器下overlay图标位置不变化的问题

    首先要创建一个工具栏.并为工具栏中的放大.缩小button定义事件. <div id="toolbar" style="float:left;margin-top: ...

  4. harbar仓库的接口测试

    一.接口测试命令 api接口文档:https://github.com/goharbor/harbor/blob/release-1.7.0/docs/swagger.yaml 1)查看所属项目的信息 ...

  5. 二、SQL Server 分页

    一.SQL Server 分页 --top not in方式 select top 条数 * from tablename where Id not in (select top 条数*页数 Id f ...

  6. "=="、equals、hashCode之间的区别

    1. "=="分为两种情况: (1) 基本数据类型,比较的是其对应的值是否相等: (2) 引用类型,比较的是他们在内存中存放的地址(或者说,是否指向同意对象). 2. equals ...

  7. 【LeetCode】设计题 design(共38题)

    链接:https://leetcode.com/tag/design/ [146]LRU Cache [155]Min Stack [170]Two Sum III - Data structure ...

  8. struts2中的Action实现的三种方式

    Action类创建方式有哪些? 方式一:直接创建一个类,可以是POJO,即原生Java类,没有继承任何类,也没有实现任何接口 这种方式使得strust2框架的代码侵入性更低,但是这种方式是理想状态,开 ...

  9. Spring---基础配置

    1.@Scope 1.1.描述了Spring容器如何新建Bean的实例: 1.2.@Scope(value="") value值有: 1.2.1.singleton 一个Sprin ...

  10. JavaWeb(一):Java技术概览

    一.Java技术体系 在早期,Java被称为Java开发工具包或JDK,是一门与平台(由一组 必需的API组成)紧密耦合的语言. 从1998年底的1.2版本开始,Java技术栈被分割为下面关键部分: ...