第一场难得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)的更多相关文章

  1. Codeforces Round #261 (Div. 2)[ABCDE]

    Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...

  2. Codeforces Round #261 (Div. 2) B

    链接:http://codeforces.com/contest/459/problem/B B. Pashmak and Flowers time limit per test 1 second m ...

  3. Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP

    http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35  36组数据 ...

  4. Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida&#39;s problem(求逆序数对)

    题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...

  5. Codeforces Round #261 (Div. 2) - E (459E)

    题目连接:http://codeforces.com/contest/459/problem/E 题目大意:给定一张有向图,无自环无重边,每条边有一个边权,求最长严格上升路径长度.(1≤n,m≤3 * ...

  6. Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题

    题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...

  7. 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 ...

  8. Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP

    题意:n个点,m条边,每条边有一个权值,找一条边数最多的边权严格递增的路径,输出路径长度. 解法:先将边权从小到大排序,然后从大到小遍历,dp[u]表示从u出发能够构成的严格递增路径的最大长度. dp ...

  9. 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). 解法:分别从左到右,由右到 ...

随机推荐

  1. CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。

    firewall:systemctl start firewalld.service#启动firewallsystemctl stop firewalld.service#停止firewallsyst ...

  2. 6)Java中String类

    1)String对象的初始化   由于String对象特别常用,所以在对String对象进行初始化时,Java提供了一种简化的特殊语法,格式如下:     String s = “abc”;     ...

  3. ASP.NET中前台调用后台的方法

    学习文章:http://www.cnblogs.com/kingteach/archive/2010/11/12/1875633.html 练习代码: 前台: <html xmlns=" ...

  4. AngularJs记录学习01

    <!doctype html> <html ng-app="myapp"> <head> <meta http-equiv="C ...

  5. 19.python的编码问题

    在正式说明之前,先给大家一个参考资料:戳这里 文章的内容参考了这篇资料,并加以总结,为了避免我总结的不够完善,或者说出现什么错误的地方,有疑问的地方大家可以看看上面那篇文章. 以下说明是针对于pyth ...

  6. 从基础开始,从一个SQLHelper开始

    最开始考虑的问题有这三点: 1.Access和SQLServer都要能用. 2.尽量简单,清晰. 3.性能不出大问题. public class SQLHelp { #region 私有域 priva ...

  7. instanceof、==号、Objetc类

    1)instanceof: 判断某个对象是否为某个类的实例,注意多态的运用,一个父类引用指向子类的对象,根据继承,子类就是父类,所以子类也可以看做是父类的一个实例.  形式:引用 instanceof ...

  8. Java当中的异常

    异常:中断了正常指令流的事件,是JVM虚拟机产生的对象 异常是程序运行时产生的,和编译无关 class Test{ public static void main(String args[]){ Sy ...

  9. C++类实现三维数组算法

    在学习北京大学教授的<程序设计实习 / Practice on Programming>中,遇到了一个习题,花了很长时间研究,现在分享出来: 课题地址:https://class.cour ...

  10. python 实现求和、计数、最大最小值、平均值、中位数、标准偏差、百分比。

    import sys class Stats: def __init__(self, sequence): # sequence of numbers we will process # conver ...