Codeforces Round #261 (Div. 2)
第一场难得DIV2简单+AK人数多;
E:给出一张图,求最多的边数,满足:在这个边的集合中后面的边的权值大于前面的边;
思路:我们将图按权值排列,以为只可能边权值小的跟新权值大的所以对于一条边我们只跟新一次,所以是O(N);
我们这里用两个数组进行跟新维护:
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#define N 444444
struct node
{
int u,v,w;
};
node e[N]; int pre[N],dp[N];
using namespace std;
int cmp(node a,node b){
return a.w<b.w;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for (int i=;i<=m;i++)
scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
sort(e+,e+m+,cmp); for (int i=;i<=m;i++)
{
int j=i+;
while (e[j].w==e[i].w&&j<=m) j++;
for (int k=i;k<j;k++) dp[e[k].v]=max(dp[e[k].v],pre[e[k].u]+);
for (int k=i;k<j;k++) pre[e[k].v]=max(pre[e[k].v],dp[e[k].v]);
i=j-;
}
int ans=;
for (int i=;i<=n;i++) ans=max(ans,pre[i]);
printf("%d\n",ans);
return ;
}
D:题目有点绕;
做法:我们先对HASH,求出两个数组L,R分别表示从左到右,从右到左:F(1,I,AI),F(J,N,AJ);
然后对于F[1,I,AI]求出I<J<=N中F[J,N,AJ]<F[1,I,AI]的个数;对于这种求区间的问题,树状数组就好。
我这里用map hash
然后我是从右往左的顺序统计的,做的时候脑残
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<iostream>
#include<vector>
#include<math.h>
#include<map>
#define inf 0x3f3f3f
using namespace std;
map<int,int>mp;
map<int,int>mp2;
typedef long long ll;
int n;
#define N 1023456
int a[N];
int b[N];
int c[N];
int r[N];
int l[N];
int f[N];
int lowbit(int x)
{
return x&(-x);
} void update(int x)
{
while (x<=n)
{
f[x]+=;
x+=lowbit(x);
}
} ll sum(int x)
{
ll s=;
while (x)
{
s+=f[x];
x-=lowbit(x);
}
return s;
} int main()
{
scanf("%d",&n);
mp.clear();
mp2.clear();
int t=;
for (int i=;i<=n;i++) {
scanf("%d",&a[i]);
if (!mp[a[i]]) mp[a[i]]=++t;
} for (int i=n;i>=;i--)
r[i]=b[mp[a[i]]]++; ll ans=;
for (int i=;i<=n;i++)
l[i]=c[mp[a[i]]]++; for (int i=;i<=n;i++)
{l[i]++;r[i]++;} //for (int i=1;i<=n;i++) cout<<l[i]<<" "<<r[i]<<endl;
for (int i=n-;i>=;i--)
{
update(r[i+]);
ans+=sum(l[i]-);
//printf("%d\n",ans);
} cout<<ans;
return ;
}
C:还没看懂,好难^^
B:q求最大的差值,注意全相等的情况=N*(N-1)/2;
#include<string>
#include<iostream>
#include<vector>
#include<math.h>
#define inf 0x3f3f3f
using namespace std;
int n; int a[];
int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++) scanf("%d",&a[i]);;
sort(a+,a+n+);
int mm=a[n];
int m=a[];
long long t1=;
long long t2=;
for (int i=;i<=n;i++)
{
if (a[i]==mm)t1++;
if (a[i]==m) t2++;
}
if (mm!=m) cout<<mm-m<<" "<<t1*t2<<endl;
else
{
long long t1=n; cout<<mm-m<<" "<<t1*(t1-)/<<endl;
}
return ;
}
A:正方形。。
乱搞,HACK点居多,当点在一条线上,分别考虑
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<iostream>
#include<vector>
#include<math.h>
#define inf 0x3f3f3f
using namespace std;
int n;
int main()
{
int x1,x2,yy1,y2;
cin>>x1>>yy1>>x2>>y2; if (x1==x2&&yy1==y2) {cout<<-<<endl;return ;}
if (x1!=x2&&yy1!=y2){
if (abs(y2-yy1)!=abs(x1-x2))
{
cout<<-;
return ;
}
cout<<x1<<" "<<y2<<" "<<x2<<" "<<yy1<<endl;
return ;
} if (yy1>y2) swap(yy1,y2);
if (x1==x2)
{
int b=y2-yy1;
cout<<x1+b<<" "<<yy1<<" "<<x2+b<<" "<<yy1+b<<endl;
return ;
}
else
{
if (x1>x2) swap(x1,x2);
int b=x2-x1;
cout<<x1<<" "<<yy1+b<<" "<<x2<<" "<<yy1+b<<endl;
return ;
}
return ;
}
终于出了灰的坑
Codeforces Round #261 (Div. 2)的更多相关文章
- Codeforces Round #261 (Div. 2)[ABCDE]
Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...
- Codeforces Round #261 (Div. 2) B
链接:http://codeforces.com/contest/459/problem/B B. Pashmak and Flowers time limit per test 1 second m ...
- Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP
http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35 36组数据 ...
- Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida's problem(求逆序数对)
题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...
- Codeforces Round #261 (Div. 2) - E (459E)
题目连接:http://codeforces.com/contest/459/problem/E 题目大意:给定一张有向图,无自环无重边,每条边有一个边权,求最长严格上升路径长度.(1≤n,m≤3 * ...
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...
- Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)
题目链接:http://codeforces.com/problemset/problem/459/A A. Pashmak and Garden time limit per test 1 seco ...
- Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP
题意:n个点,m条边,每条边有一个权值,找一条边数最多的边权严格递增的路径,输出路径长度. 解法:先将边权从小到大排序,然后从大到小遍历,dp[u]表示从u出发能够构成的严格递增路径的最大长度. dp ...
- Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --树状数组
题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求有多少对这样的(i,j). 解法:分别从左到右,由右到 ...
随机推荐
- S5PV2210
http://www.doc88.com/p-773451739254.html CAN转换器 CAN总线信息转换输出装置 基于车载CAN总线的倒车雷达单元设计[图] http://www.doc88 ...
- API - .add()
jQuery的 .add 很像一个collection, 官方的这个demo很形象的表达了这个意思. <!doctype html> <html lang="en" ...
- 简单翻译和补充:1. GNU ARM Eclipse
原文链接: GNU ARM Eclipse GNU 介绍: GNU 计划,又称革奴计划,是由RichardStallman在1983年9月27日公开发起的.它的目标是创建一套完全自由的操作系统.Ric ...
- 17.python自定义函数
什么是函数,函数说白了就是将一系列代码封装起来,实现代码的重用. 什么是代码重用? 假设我有这样的需求: 但是我还是觉得太麻烦了,每次想吃饭的时候都要重复这样的步骤.此时,我希望有这样的机器:
- C基础 数据序列化简单使用和讨论
前言 C中对序列化讨论少, 因为很多传输的内容都有自己解析的轮子. 对于序列化本质是统一编码, 统一解码的方式. 本文探讨是一种简单的序列化方案. 保证不同使用端都能解析出正确结果. 在文章一开始, ...
- memcached 高级机制(二)
memcached删除机制 a) (1)有内存机制里说明了,这里会运用到LRU删除机制.我们知道,当我们在add或set一个值时,我们会设置这个值得期限.当某个值过期后,这个值并没有从内存中删除,我们 ...
- 浅谈HAL
参考:http://blog.csdn.net/mr_raptor/article/details/8074549 代码实现:http://blog.csdn.net/mr_raptor/articl ...
- Android 实现子View的状态跟随父容器的状态
最近自学着做东西,需要做一个效果,就是我ListView的Item点击下或者选中的时候,我Item里面的各个组件的状态要和我Item的状态保持一直,这样我就可以用XML,去根据组件的不同状态去实现不同 ...
- start apache2 failed in Ubuntu
Invalid command 'WSGIReloadMechanism', perhaps misspelled or defined by a module not included in the ...
- 46.谈谈SDRAM的作用
SDRAM这个至今还在用的存储器,虽然被后来的DDR取代,掌握好它还是很重要的.之前在调试时,确实费了好大劲,它的复杂性毋庸置疑,一般人要想弄懂他,得花1个月左右吧,至少我这么认为.话说回来,SDRA ...