CF140C New Year Snowmen

#include <bits/stdc++.h>
using namespace std;
#define gc getchar()
#define rep(i , x, y) for(int i = x;i <= y;++ i)
#define sep(i , x, y) for(int i = x;i >= y;-- i)
#define PII pair<int,int>
#define mk make_pair
#define fi first
#define se second
const int maxN = 1e5 + 7; inline int gi() {
int x = 0,f = 1;char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}
return x * f;
} int cnt[maxN];
int a[maxN];
priority_queue<PII> q;
struct Ans {
int x,y,z;
}b[maxN];
int n; void Read() {
n = gi();
rep(i , 1, n) a[i] = gi();
return;
} void Pre() {
sort(a + 1,a + n + 1);
rep(i , 1, n) {
int p = lower_bound(a + 1,a + n + 1,a[i]) - a;
cnt[p] ++;
}
for(int i = 1;i <= n;++ i) {
if(cnt[i]) q.push(mk(cnt[i] , i));
}
} void Solve() {
int k = 0;
while(q.size() >= 3) {
int x = q.top().se;q.pop();
int y = q.top().se;q.pop();
int z = q.top().se;q.pop();
b[++ k] = (Ans) {a[x] , a[y], a[z]};
if(b[k].z > b[k].y) swap(b[k].z , b[k].y);
if(b[k].y > b[k].x) swap(b[k].x , b[k].y);
if(b[k].z > b[k].y) swap(b[k].z , b[k].y);
cnt[x] --;if(cnt[x]) q.push(mk(cnt[x] , x));
cnt[y] --;if(cnt[y]) q.push(mk(cnt[y] , y));
cnt[z] --;if(cnt[z]) q.push(mk(cnt[z] , z)); }
printf("%d\n",k);
rep(i , 1, k) {
printf("%d %d %d\n",b[i].x,b[i].y,b[i].z);
}
} int main() {
Read();
Pre();
Solve();
return 0;
}

CF161B Discounts

#include <bits/stdc++.h>
using namespace std;
#define gc getchar()
#define rep(i , x, y) for(int i = x;i <= y;++ i)
#define sep(i , x, y) for(int i = x;i >= y;-- i)
#define PII pair<int,int>
#define fi first
#define se second
#define mk make_pair
#define dbug(x) cout << "DEbug: " << x << '\n'; inline int gi() {
int x = 0 ,f = 1;char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}
return x * f;
} int n, k;
const int maxN = 1e3 + 7; struct Node {
int id, c;
}a[maxN];
int t[maxN]; bool cmp(Node a, Node b) {
return a.c > b.c;
} bool vis[maxN];
int ans[maxN]; void Solve() {
double ans1 = 0;
int n = gi(), k = gi();
for(int i = 1;i <= n;++ i) {
a[i].id = i;
a[i].c = gi();
ans1 += a[i].c;
t[i] = gi();
}
sort(a + 1, a + n + 1,cmp);
int num = 0;
for(int i = 1;i <= n;++ i) {
if(num < k - 1 && t[a[i].id] == 1) {
vis[i] = true;
ans[++ num] = a[i].id;
ans1 -= 1.0 * a[i].c / 2;
}
}
bool flag = false;
int minn = 0x7fffffff;
for(int i = 1;i <= n;++ i) {
if(!vis[i]) {
if(t[a[i].id]== 1) {
flag = true;
minn = min(minn ,a[i].c);
}
}
}
int tot = num;
for(int i = 1;i <= n;++ i) {
if(!vis[i]) {
if(tot == k - 1) break;
tot ++;
ans[tot] = a[i].id;
vis[i] = true;
}
}
if(flag) ans1 -= 1.0 * minn / 2;
cout << ans1 << '\n';
for(int i = 1;i < k;++ i) {
printf("1 %d\n",ans[i]);
}
int cnt = 0;
for(int i = 1;i <= n;++ i) {
if(!vis[i]) cnt ++;
}
printf("%d ",cnt);
for(int i = 1;i <= n;++ i) {
if(!vis[i]) {
printf("%d ",a[i].id);
}
}
} int main() {
Solve();
return 0;
}

P1842 奶牛玩杂技

#include <bits/stdc++.h>
using namespace std;
#define gc getchar()
#define rep(i , x, y) for(int i = x;i <= y;++ i)
#define sep(i , x, y) for(int i = x;i >= y;-- i)
#define int long long
const int inf = 0x7fffffff; inline int gi() {
int x = 0,f = 1;char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}
return x * f;
}
const int maxN = 100000 + 7; struct Node {
int w, s;
}a[maxN]; bool cmp(Node a , Node b) {return a.s + a.w > b.s + b.w;} signed main() {
int n = gi();
rep(i , 1, n) {
a[i].w = gi();
a[i].s = gi();
}
sort(a + 1 , a + n + 1, cmp);
int ans = -inf;
int sum = 0;
sep(i , n, 1) {
ans = max(ans , sum - a[i].s);
sum += a[i].w;
}
printf("%lld",ans);
return 0;
}

最新文章

  1. ImageLoader配合ImageSwitcher的使用
  2. 更新centos curl
  3. Codeforces Round #282 Div.1 B Obsessive String --DP
  4. js判断访问来源
  5. SPOJ #442 Searching the Graph
  6. Memcached使用
  7. Computer Vision的尴尬---by林达华
  8. http server v0.1_http_server.c
  9. Simple screenshot that explains the singleton invocation.
  10. 【转】 iOS开发UI篇—控制器的View的创建
  11. 无锁atomicInteger
  12. python解决上楼梯问题
  13. BPM与OA区别
  14. 细说Django的中间件
  15. ssm 连接两个数据库
  16. Netty 源码剖析之 unSafe.read 方法
  17. 【BZOJ1297】[SCOI2009]迷路(矩阵快速幂)
  18. javaweb项目运行时生成的Servers项目作用
  19. iterm2 学习笔记
  20. VSCode中C/C++库文件的配置

热门文章

  1. Entity Framework 学习系列(1) - 认识理解Entity Framework
  2. Dubbo(三):框架设计
  3. Prime Path POJ-3126
  4. 使用MHA实现MySQL主从复制高可用
  5. 关于OA流程相关数据表的设计
  6. a属性+DOM创建回流+动画运动+
  7. ios、安卓前端兼容性
  8. Java 流程控制 之 分支结构——条件判断语句
  9. Springboot生成二维码并下载图片png支持打包成zip
  10. Cheat Engine 基本用法