2018 China Collegiate Programming Contest Final (CCPC-Final 2018)(A B G I L)
A:签到题,正常模拟即可。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
struct node{
int id, time;
};
node a[maxn];
bool cmp(const node &a, const node &b){
if(a.id^b.id) return a.id < b.id;
else return a.time < b.time;
}
int main()
{
std::ios::sync_with_stdio(false);
int n, m, t;
cin >> t;
for(int cas = ;cas <= t;cas++)
{
cin >> n >> m;
for(int i = ;i < n;i++) cin >> a[i].id;
for(int i = ;i < n;i++) cin >> a[i].time;
int ans = ;sort(a, a + n, cmp);
int sum = ;
for(int i = ;i < n;i++)
{
if(sum + a[i].time <= m) sum += a[i].time, ans ++;
else break;
}
cout << "Case " << cas << ": ";
cout<< ans << endl;
}
return ;
}
B:对于差值尽量小的问题,可以采用枚举最小值,然后使得最大值尽量小。
首先二分图判定,然后分块,求出每块的光明状态的最大最小值,黑暗状态的最大最小值,然后按分块编号塞到线段树离维护最大值,然后对这2*cnt个块由最小值从小到大进行排序,枚举每个块的最小值,然后更新答案,然后将这个块的最大值在线段树中删去,当某个块的光明状态和黑暗状态都被删去的时候,就不用继续枚举了。
#include<bits/stdc++.h>
#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
using namespace std;
typedef long long ll;
const int maxn = 5e5 + ;
const int INF = 0x3f3f3f3f;
struct node{
int maxx, minn, id;
bool operator <(const node &b)const{
return minn < b.minn;
}
};
struct tree{
pair<int, int> p[];
int val;
void deleted(int x)
{
if(p[].first == x) p[].second = INF;
else p[].second = INF;
}
};
int n, m, t;
vector<int> G[maxn];
int L[maxn], D[maxn];
int color[maxn] , vis[maxn], cnt;
tree T[maxn << ];
node A[maxn];
bool flag;
int num[maxn];
void pushup(int rt)
{
T[rt].val = max(T[ls].val, T[rs].val);
}
void build(int l, int r, int rt)
{
if(l == r)
{
T[rt].p[] = {A[l].minn, A[l].maxx};
T[rt].p[] = {A[l + cnt].minn, A[l + cnt].maxx};
T[rt].val = min(A[l].maxx, A[l + cnt].maxx);
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){
T[rt].deleted(v);
T[rt].val = min(T[rt].p[].second, T[rt].p[].second);
return;
}
int mid = lr2;
if(k <= mid) update(k, v, lson);
else update(k, v ,rson);
pushup(rt);
}
bool dfs(int v, int c, int id){
color[v] = c;
vis[v] = id;
for(int i = ;i < G[v].size();i++)
{
int u = G[v][i];
if(color[u] == c) return false;
if(!color[u]){
if(!dfs(u, - c, id)) return false;
}
}
return true;
}
void init()
{
for(int i = ;i <= n;i++) G[i].clear();
fill(color, color + n + , );
fill(vis, vis + n + , );
fill(num, num + n + , );
cnt = ;flag = false;
}
int main()
{
std::ios::sync_with_stdio(false);
cin >> t;
for(int cas = ; cas <= t;cas++)
{
cin >> n >> m;
init();
for(int i = ;i < m;i++)
{
int a, b; cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
for(int i = ;i <= n;i++) cin >> L[i] >> D[i];
for(int i = ;i <= n;i++)
{
if(!vis[i])
{
++cnt;
if(!dfs(i, , cnt))
{
flag = true;
break;
}
}
}
cout << "Case " << cas << ": ";
if(flag){
cout << "IMPOSSIBLE" << endl;
continue;
}
for(int i = ;i <= * cnt;i++)
{
A[i].maxx = , A[i].minn = INF;
}
for(int i = ;i <= n;i++){
int x = vis[i];
if(color[i] == )
{
A[x].id = x;
A[x].maxx = max(A[x].maxx, L[i]);
A[x].minn = min(A[x].minn, L[i]);
A[x + cnt].id = x;
A[x + cnt].maxx = max(A[x + cnt].maxx, D[i]);
A[x + cnt].minn = min(A[x + cnt].minn, D[i]);
}
else{
A[x].id = x;
A[x].maxx = max(A[x].maxx, D[i]);
A[x].minn = min(A[x].minn, D[i]);
A[x + cnt].id = x;
A[x + cnt].maxx = max(A[x + cnt].maxx, L[i]);
A[x + cnt].minn = min(A[x + cnt].minn, L[i]);
}
}
build(, cnt, );
sort(A + , A + * cnt + );
int ans = INF;
for(int i = ;i <= * cnt;i++)
{
ans = min(ans, T[].val - A[i].minn);
num[A[i].id]++;
if(num[A[i].id] == ) break;
update(A[i].id, A[i].minn, , cnt, );
}
cout << ans << endl;
}
return ;
}
G:题目大意:在一个n * m的土地,要在一个子矩形内放稻草人,稻草人必须被稻草包围,问合法的方法有多少种?
问题其实可以转化为:在n * m的草地上,选出一块子矩形,这个子矩形来放满稻草人必须被包括在n * m的矩形内。可以行和列分开考虑,(行的方案数) * (列的方案数)就是答案。一行可以选4个点,里面两个点是子矩形的宽的边界(列的边界),发现这样能确定一个子矩形的列的情况,但还有一种遗漏,就是只有一列的子矩形,这种情况只需要选三个点,所以是c[m][3] + c[m][4], 这样就确定了列的所有方案,行的方案跟列的方案类似。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
const int mod = 1e9 + ;
ll C[maxn][];
void init()
{
C[][] = ;
for(int i = ; i <= maxn;i++)
{
C[i][] = ;
for(int j = ; j <= ;j++)
C[i][j] = (C[i - ][j] + C[i - ][j - ]) % mod;
}
}
int main()
{
std::ios::sync_with_stdio(false);
int n, m ,t;
cin >> t;
init();
for(int cas = ;cas <= t;cas++)
{
cin >> n >> m;
ll h = (C[n][] + C[n][]) % mod;
ll w = (C[m][] + C[m][]) % mod;
ll ans = h * w % mod;
cout << "Case "<< cas << ": ";
cout << ans << endl;
}
return ;
}
I:记录每个点的横纵坐标所在行列的点的数目,找到最大的maxx,maxy,max_x = maxx+maxy,其实消灭蟑螂的最大数目只能是max_x,或者max_x-1。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
ll n;
map<int,int> x, y;
struct node{
int x,y;
};
node a[maxn];
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin >> t;
for(int cas = ; cas <=t; cas++){
cin >> n;
x.clear();
y.clear();
for(int i = ; i <= n; i++){
cin >> a[i].x >> a[i].y;
x[a[i].x]++;
y[a[i].y]++;
}
int maxx = , maxy = ;
for(int i = ; i <= n; i++){
maxx = max(maxx, x[a[i].x]);
maxy = max(maxy, y[a[i].y]);
}
if(x.size() == || y.size() == ){
cout << "Case " << cas << ": " << n << " " << << endl;
}
else{
if(maxx == && maxy == ){
cout << "Case " << cas << ": " << << " " << n*(n-)/ << endl;
}
else{
ll x1 = , x2 = , y1 = , y2 = ;
map<int,int>::iterator it;
for(it = x.begin(); it != x.end(); it++){
if(it->second == maxx) x1++;
else if(it->second == maxx - ) x2++;
}
for(it = y.begin(); it != y.end(); it++){
if(it->second == maxy) y1++;
else if(it->second == maxy - ) y2++;
}
ll ans1 = , ans2 = ;
ans1 = x1 * y1;
ans2 = x2 * y1 + x1 * y2;
for(int i = ; i <= n; i++){
if(maxx + maxy == x[a[i].x] + y[a[i].y]){
ans1--;
ans2++;
}
else if(maxx + maxy - == x[a[i].x] + y[a[i].y]){
ans2--;
}
}
if(ans1){
cout << "Case " << cas << ": " << maxx + maxy << " " << ans1 << endl;
}
else{
cout << "Case " << cas << ": " << maxx + maxy - << " " << ans2 << endl;
}
}
}
} }
L:贪心 + 分类讨论 + 暴力。小于等于11直接impossible, 然后奇数可以拆成 2 2 2 3 + 偶数, 偶数可以拆成2 2 2 2 + 偶数,对最后的偶数暴力分解即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool check(ll x)
{
int n = sqrt(x);
for(int i = ;i <= n;i++){
if(x % i == )return false;
}
return true; }
void print(ll n)
{
for(ll i = n - ;i >= ;i--){
if(check(i) && check(n - i)){
cout << " " << i << " " << n - i << endl;
return;
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin >> t;
int cnt = ;
while(t--)
{
ll n;
cin >> n;
cout << "Case "<< cnt++ <<": ";
if(n > )
{
if(n & )
{
n -= 9LL;
cout << "2 2 2 3";
print(n);
}
else{
n -= 8LL;
cout << "2 2 2 2";
print(n);
}
}
else cout << "IMPOSSIBLE" << endl;
}
return ;
}
2018 China Collegiate Programming Contest Final (CCPC-Final 2018)(A B G I L)的更多相关文章
- 2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定理
2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定 ...
- 2018 China Collegiate Programming Contest Final (CCPC-Final 2018)
Problem A. Mischievous Problem Setter 签到. #include <bits/stdc++.h> using namespace std; #defin ...
- 模拟赛小结:2018 China Collegiate Programming Contest Final (CCPC-Final 2018)
比赛链接:传送门 跌跌撞撞6题摸银. 封榜后两题,把手上的题做完了还算舒服.就是罚时有点高. 开出了一道奇奇怪怪的题(K),然后ccpcf银应该比区域赛银要难吧,反正很开心qwq. Problem A ...
- 2016 China Collegiate Programming Contest Final
2016 China Collegiate Programming Contest Final Table of Contents 2016 China Collegiate Programming ...
- The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540
Secrete Master Plan Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- The 2015 China Collegiate Programming Contest Game Rooms
Game Rooms Time Limit: 4000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- 2018 German Collegiate Programming Contest (GCPC 18)
2018 German Collegiate Programming Contest (GCPC 18) Attack on Alpha-Zet 建树,求lca 代码: #include <al ...
- (寒假GYM开黑)2018 German Collegiate Programming Contest (GCPC 18)
layout: post title: 2018 German Collegiate Programming Contest (GCPC 18) author: "luowentaoaa&q ...
- 2017 China Collegiate Programming Contest Final (CCPC 2017)
题解右转队伍wiki https://acm.ecnu.edu.cn/wiki/index.php?title=2017_China_Collegiate_Programming_Contest_Fi ...
随机推荐
- c#批量插入
一.创建一个用来测试的数据库和表 USE [Test] GO /****** Object: Table [dbo].[student] Script Date: 2019/4/11 15:38:59 ...
- [LOJ3123] CTSC2019重复
Description 给定一个⻓为 n 的字符串 s , 问有多少个⻓为 m 的字符串 t 满足: 将 t 无限重复后,可以从中截出一个⻓度为 n 且字典序比 s 小的串. m ≤ 2000 n ≤ ...
- bjsxt学习笔记:Dubbo
一.Dubbo诞生背景(摘自Dubbo官网-入门-背景) 二.Dubbo架构图(摘自Dubbo官网-入门-架构) 三.Dubbo核心依赖(jar包):dubbo.zkclient 四.Dubbo项目搭 ...
- hdu 6298 Maximum Multiple(规律)
hdu6298 Maximum Multiple 题目传送门 题意: 给你一个整数n,从中找出可以被n整除的三个数x,y,z: 要求x+y+z=n,且x*y*z最大. 思路: 开始一看T到1e6,n也 ...
- poj2385 Apple Catching (线性dp)
题目传送门 Apple Catching Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 154 ...
- 如何优雅的实现DML批量操作
如何优雅的实现DML批量操作(转载) 昨天处理了一个业务同学的数据需求,简单来说就是对一张大表做一下数据清理,数据量在8千万左右,需要保留近一个月的数据,大概是400万左右. 对于数据的删除处理,尤其 ...
- 使用easyui框架 设置时间格式
之前做的一个商城项目,后台系统页面使用Easyui做的,记录一个当时卡住的地方: 首先通过<table>标记创建数据网格(datagrid) <table class="e ...
- XILINX FPGA 开发板 XC3S250E 核心板 学习板+12模块
北京太速科技有限公司为广大合作单位特设海外代购业务,主要包括各类板卡.相机.传感器.仪器仪表.专用芯片等.代购业务仅收取基本的手续费. 北京太速科技有限公司在线客服:QQ:448468544 淘宝网站 ...
- Shell03---流程控制
目录 Shell03---流程控制 1. 流程控制语句if基本概述 2. 流程控制语句if文件比较 3. 流程控制语句if整数比较 4. 流程控制语句if字符比较 5. 流程控制语句if正则比较 6. ...
- poj 1845 Sumdiv (等比求和+逆元)
题目链接:http://poj.org/problem?id=1845 题目大意:给出两个自然数a,b,求a^b的所有自然数因子的和模上9901 (0 <= a,b <= 50000000 ...