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. Java数组模拟栈

    一.概述 注意:模拟战还可以用链表 二.代码 public class ArrayStack { @Test public void test() { Stack s = new Stack(5); ...

  2. 两台centos,用yum install 安装,一台成功,一台失败

    记录一下问题: 两台centos,用yum install 安装软件,一台成功,一台失败 第一步:查看yum源  yum repolist enabled 疑问:centos安装的方法一致,但yum源 ...

  3. hdu 1828 Picture(线段树轮廓线)

    Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  4. Android APP 登陆模块

    首先我想强调一点.这个登陆的模块最好是放在另外一个线程里面来实现.否则有可能会爆出一系列的问题, 然后再与主UI 交互.这样就不会爆ANR异常 1.对于登陆模块的.首先大体的逻辑肯定是要清晰的.    ...

  5. Redis设计与实现 -- 链表与字典

    1. 链表 1.1 链表的结构 在 Redis 中,链表的实现是双向链表,除此之外与常规的链表不同的是它还有三个函数指针,dup 函数用于复制链表节点所保存的值,free 函数用于释放链表节点保存的值 ...

  6. 72.Minimum Window Substring(最小子串窗口)

    Level:   Hard 题目描述: Given a string S and a string T, find the minimum window in S which will contain ...

  7. Spring Data Redis实战之提供RedisTemplate

    参考: http://www.cnblogs.com/edwinchen/p/3816938.html 本项目创建的是Maven项目 一.pom.xml引入dependencies <depen ...

  8. Java 8实战之读书笔记三:函数式数据处理

    二.函数式数据处理 第4章 引入流 流是Java API的新成员,它允许你以声明性方式处理数据集合(通过查询语句来表达,而不是临时编写一个实现). 示例: import static java.uti ...

  9. React Native实践总结一

    一.React的世界观1.通过改变state来改变视图视图不用考虑如何改变自己,把state画出来即可.2.变量不可变通过创建一个新的state来更改state,使得变更可追踪,不容易因为其他部分修改 ...

  10. 浏览器报406 错误:The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers

    The resource identified by this request is only capable of generating responses with characteristics ...