The 13th Chinese Northeast Collegiate Programming Contest(B C E F H J)
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)的更多相关文章
- The 13th Chinese Northeast Collegiate Programming Contest
题解: solution Code: A. Apple Business #include<cstdio> #include<algorithm> #include<ve ...
- 【The 13th Chinese Northeast Collegiate Programming Contest E题】
题目大意:给定一棵 N 个点的树,边有边权,定义"线树"为一个图,其中图的顶点是原树中的边,原树中两条有公共端点的边对应在线图中存在一条边,边权为树中两条边的边权和,求线图的最小生 ...
- 【The 13th Chinese Northeast Collegiate Programming Contest H 题】
题目大意:NOIP2018d1t1 支持 M 次区间查询答案和区间修改操作. 题解: 首先考虑不带区间修改的情况.从左到右进行考虑,发现对于第 i 个数来说,对答案的贡献仅仅取决于第 i-1 个数的大 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 = { ...
- 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 ...
随机推荐
- Java-多线程第三篇3种创建的线程方式、线程的生命周期、线程控制、线程同步、线程通信
1.Java使用Thread类代表线程. 所有的线程对象必须是Thread类或其子类的实例. 当线程继承Thread类时,直接使用this即可获取当前线程,Thread对象的getName() ...
- U33405 纽约 (二分)
[题目描述] 牧民 Azone 需要多次往返于两个草场之间运输家当.为了顺利转场,Azone 决定花费 w元津巴布韦币,购买一辆载重为 w 的汽车.共有 n 件家具需要搬运,每件家具的重量为 wi ...
- Windows组决策
https://blog.csdn.net/wangjunjun2008/article/details/82426587
- android 完全退出应用程序(经过严格验证)
今天解决了如何彻底结束Android应用程序的方法.网上有很多的参考方法,什么finish():android.os.Process.killProcess(android.os.Process.my ...
- style中各种选择器
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 在html模板里面加python函数(simple_tag与filter)
自定义函数 simple_tag a. app下创建templatetags目录 b. 任意xxoo.py文件 c. 创建template对象 register d. @register.simple ...
- SR-IOV
SR-IOV 来源 http://blog.csdn.net/liushen0916/article/details/52423507 摘要: 介绍SR-IOV 的概念.使用场景.VMware 和 K ...
- ansiable介绍及安装
ansible介绍: Ansible默认通过 SSH 协议管理机器. ssh协议介绍:https://www.cnblogs.com/yaozhiqiang/p/9944894.html 安装ansi ...
- XMPP即时通讯协议使用(十三)——获取当前在线用户或关闭指定用户
1.开启REST API插件或根据需求修改其插件源码: 2.添加服务器->服务器管理->系统属性中添加 plugin.restapi.enabled=true 3.pom依赖 <de ...
- rpmcache - 缓存 RPM 打包头部
SYNOPSIS rpmcache [ PACKAGE_NAME ... ] DESCRIPTION rpmcache 遍历文件树,可能通过 FTP 使用远程文件,使用 glob(7) 表达式过滤路径 ...