http://codeforces.com/contest/701

A - Cards

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
struct node{
int x,y;
node(int x_=,int y_=):x(x_),y(y_){}
bool operator < (const node & a) const{
return x==a.x?y<a.y:x<a.x;
}
}p[];
int n;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&p[i].x);
p[i].y=i;
}
sort(p+,p+n+);
for(int i=;i<=n/;i++){
printf("%d %d\n",p[i].y,p[n-i+].y);
}
return ;
}

B - Cells Not Under Attack

题意:起始n*n的矩阵都填满,每次询问,询问的点消除当前点所在行和列的所有物品,输出每次询问后剩下的物品数

思路:如果当前行没有删除过,则现在删除n-(已经删除过的列数)

同理当前列:n-(已经删除过的行数)

如果都没有删除过:两种情况相加+1

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// } int l[N],r[N];
int main(){
int n,m;
scanf("%d%d",&n,&m);
int cntl=,cntr=;
LL ans;
ans=(LL)n*n;
// cout<<ans<<endl;
while(m--){
int a,b;
scanf("%d%d",&a,&b);
if(r[a]==&&l[b]==){
ans-=(n-cntl+n-cntr-);
cntr++;
cntl++;
r[a]++;
l[b]++;
printf("%I64d ",ans);
continue;
}
if(r[a]==){
ans-=(n-cntl);
cntr++;
r[a]++;
}
if(l[b]==){
ans-=(n-cntr);
cntl++;
l[b]++;
}
printf("%I64d ",ans);
}
return ;
}

C - They Are Everywhere

题意:计算包含母串中所有不同字母的最小子串长度

思路:设置一个左端点,右端点,判断一下合不合适就可以了

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
int m[];
int main(){
int n;
string s;
scanf("%d",&n);
cin>>s;
int l=,r=;
int leng=(int)s.size();
for(int i=;i<leng;i++){
if(m[s[i]]==){
r=i;
}
m[s[i]]++;
}
int ans=inf;
for(int i=r+;i<leng;i++)
m[s[i]]--;
// cout<<"sdf"<<endl;
while(r<leng){
while(m[s[l]]>){
m[s[l]]--;
l++;
}
ans=min(ans,r-l+);
r++;
// cout<<r<<endl;
m[s[r]]++;
}
printf("%d\n",ans);
return ;
}

D - As Fast As Possible

题意:n个人去距离为l的地方,人的速度为v1 车的速度v2 车一次最多载k个人,求最短时间

思路:一开始想错了,最短时间应该是:车空余的时间越少,不同的人坐车时间和走路时间都一样,且每个人同时到达终点。

推下公式就可以了

难点是最少时间搞不清楚

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// } int main(){
double l,v1,v2;
int k,n;
scanf("%d%lf%lf%lf%d",&n,&l,&v1,&v2,&k);
double ans=;
int p=n/k;
if(n%k) p++;
double t=l/(p*v2-(v2-v1)/(v2+v1)*v2*(p-));
ans=(l-v2*t)/v1+t;
printf("%.10f\n",ans);
return ;
}

E - Connecting Universities

题意:n点节点,n-1条边的树,规定了树上2*k的节点,使这2*k的节点两两配对,求最长长度,每条边长度为1;

思路:

1.以这2*k个节点来看,求树的重心,再求每个点到重心的距离和

2.求每条边的贡献:两个端点所涵盖规定节点数目的最小值  也就是min(a[v],2*k-a[v])

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
#define pb push_back
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
int a[N];
vector<int>s[N];
int n,k;
LL ans;
void dfs(int u,int f){
for(int i=;i<(int)s[u].size();i++){
int v=s[u][i];
if(v==f) continue;
dfs(v,u);
a[u]+=a[v];
ans+=min(a[v],*k-a[v]);
}
return;
}
int main(){
scanf("%d%d",&n,&k);
for(int i=;i<*k;i++){
int x;
scanf("%d",&x);
a[x]=;
}
for(int i=;i<=n;i++) s[i].clear();
for(int i=;i<n-;i++){
int x,y;
scanf("%d%d",&x,&y);
s[x].pb(y);s[y].pb(x);
}
ans=;
dfs(,-);
printf("%I64d\n",ans);
return ;
}

Codeforces Round #364的更多相关文章

  1. Codeforces Round #364 (Div. 2)

    这场是午夜场,发现学长们都睡了,改主意不打了,第二天起来打的virtual contest. A题 http://codeforces.com/problemset/problem/701/A 巨水无 ...

  2. Codeforces Round #364 (Div.2) D:As Fast As Possible(模拟+推公式)

    题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...

  3. Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)

    题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...

  4. 树形dp Codeforces Round #364 (Div. 1)B

    http://codeforces.com/problemset/problem/700/B 题目大意:给你一棵树,给你k个树上的点对.找到k/2个点对,使它在树上的距离最远.问,最大距离是多少? 思 ...

  5. Codeforces Round #364 As Fast As Possible

    二分思想,对所要花费的时间进行二分,再以模拟的形式进行验证是否可行. 使用二分法,可以将一个求最优解的问题转化为一个判定问题,优雅的暴力. #include<cstdio> #includ ...

  6. Codeforces Round #364 (Div. 2) B. Cells Not Under Attack

    B. Cells Not Under Attack time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  7. Codeforces Round #364 (Div. 2) Cells Not Under Attack

    Cells Not Under Attack 题意: 给出n*n的地图,有给你m个坐标,是棋子,一个棋子可以把一行一列都攻击到,在根据下面的图,就可以看出让你求阴影(即没有被攻击)的方块个数 题解: ...

  8. Codeforces Round #364 (Div. 2) Cards

    Cards 题意: 给你n个牌,n是偶数,要你把这些牌分给n/2个人,并且让每个人的牌加起来相等. 题解: 这题我做的时候,最先想到的是模拟,之后码了一会,发现有些麻烦,就想别的方法.之后发现只要把它 ...

  9. Codeforces Round #364 (Div. 2)->A. Cards

    A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

随机推荐

  1. 内存单元按字节编址,地址0000A000H~0000BFFFH共有几个存储单元

    一般可以这样:按十六进制(bffff-a000)+1=1fff+12000H=2x16x16x16=81928192/1024=8 最后是8k或者按二进制bfff-a000=0001 1111 111 ...

  2. Java API —— 多线程(2)

    1.JDK5中Lock锁的使用 虽然我们可以理解同步代码块和同步方法的锁对象问题,但是我们并没有直接看到在哪里加上了锁,在哪里释放了锁,为了更清晰的表达如何加锁和释放锁,JDK5以后提供了一个新的锁对 ...

  3. hadoop拾遗(二)---- 文件模式

    在单个操作中处理一批文件,这是一个常见的要求.举例来说,处理日志的MapReduce作业可能需要分析一个月内包含在大量目录中的日志文件.在一个表达式中使用通配符来匹配多个文件是比较方便的,无需列举第个 ...

  4. HDU 4358 Boring counting 树状数组+思路

    研究了整整一天orz……直接上官方题解神思路 #include <cstdio> #include <cstring> #include <cstdlib> #in ...

  5. spring+hibernate+Struts2 整合(全注解及注意事项)

    最近帮同学做毕设,一个物流管理系统,一个点餐系统,用注解开发起来还是很快的,就是刚开始搭环境费了点事,今天把物流管理系统的一部分跟环境都贴出来,有什么不足的,请大神不吝赐教. 1.结构如下 2.jar ...

  6. js中的this怎么理解

    本博客供自己学习备忘, js中的this感觉很混乱,目前还有不少地方搞得不是很清楚,看到一篇不错的文章,先摘下来 this是Javascript语言的一个关键字它代表函数运行时,自动生成的一个内部对象 ...

  7. poj 2528 Mayor's posters(线段树)

    题目:http://poj.org/problem?id=2528 题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度.现在往墙上贴N张海报,每张海报的宽度是任意的, 但是必定是单位宽度的整数 ...

  8. axis : java.lang.NoSuchMethodError

    Hi friends,Iam getting the following error when deploying my app in jboss error.Iam new to axis .can ...

  9. sql server2005内存过高释放方法

    最近做了一个网站qq.115sou.com,在服务器中SQL Server占用内存非常高,加内存后,SQL Server又吃掉新加的内存,好像内存永远不够用一样,怎么办? 其实这并不一定是由于SQL ...

  10. 出现错误ActivityManager: Warning: Activity not started, its current task has been

    1.在学习两个Activity的切换时,重新把新的工程部署上模拟器时候出现错误:ActivityManager: Warning: Activity not started, its current ...