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). 解法:分别从左到右,由右到 ...
随机推荐
- VCL主要框架
TObject ->TPersistent Classes,抽象类 ->TComponent Classes,抽象类 ->TControl Controls ->TGra ...
- opensuse 安装 Anaconda3 之后出现Could not start d-bus. Can you call qdbus?
最近在安装了opensue Leap42.1之后,想要学习一下python,就安装了Anaconda3,并且将Anaconda3的安装路径添加到了PATH里,但是在重新启动系统后,出现了"C ...
- selenium+python登录登出百度,等待页面加载,鼠标定位
#coding:gbk from selenium import webdriver from selenium.webdriver.common.keys import Keys from sele ...
- flask学习
安装环境: centos 6.3 python2.6 使用easy_install安装方式: [root@localhost ~]# easy_install flask 简单的hello from ...
- js的reduce方法,改变头等函数
头等函数:把编程变成了类似搭积木的方式编码,可以使用很少的代码,实现强大的功能函数. eg: getTotal:数组的求和运算. var myArray = [1,2,3,4]; var add = ...
- Linux下编译内核配置选项简介
Code maturity level options代码成熟度选项 Prompt for development and/or incomplete code/drivers 显示尚在开发中或尚未完 ...
- hdu 5427 A problem of sorting
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5427 A problem of sorting Description There are many ...
- JavaScript高级程序设计之函数
函数实际上是对象,每个函数都是Function类型的实例. 函数是引用类型. 函数名实际上是一个指向函数对象的指针,不会与某个函数绑定. // 这种写法更能表达函数的本质 var sum = func ...
- 【EF Code First】 一对一、一对多的多重关系配置
这里使用相册Album和图片Picture的关系做示例 1,Album与Picture最基本的关系是1-n(一个相册可以有多张图片) 这时Album.Picture实体类可以这么定义 /// < ...
- 混合使用C和C++
C++作为C语言的扩展集,几乎所有的C程序都可以在C++中编译和运行,但是要注意C程序中可能使用了C++中的关键字作为变量,比如在C中:int class = 0; 但这在C++中不行.出于方便性,我 ...