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. TCL语言笔记:TCL中的数组

    一.介绍 Tcl 中的数组和其他高级语言的数组有些不同:Tcl 数组元素的索引,或称键值,可以是任意的字符串,而且其本身没有所谓多维数组的概念.数组的存取速度要比列表有优势,数组在内部使用散列表来存储 ...

  2. linux PATH环境变量

    $PATH:决定了shell将到哪些目录中寻找命令或程序,PATH的值是一系列目录,当您运行一个程序时,Linux在这些目录下进行搜寻编译链接 shell下输出path值: echo $PATH: w ...

  3. mongodb管理工具rockmongo

    mongodb的图像管理工具非常之多,我用的是rockmongo. RockMongo 是一个PHP5写的MongoDB管理工具. 主要特征: 使用宽松的New BSD License协议 速度快,安 ...

  4. POJ 水题若干

    POJ 3176 Cow Bowling 链接: http://poj.org/problem?id=3176 这道题可以算是dp入门吧.可以用一个二维数组从下向上来搜索从而得到最大值. 优化之后可以 ...

  5. 传感器(3)传感器的X,Y,Z轴

    设备正面水平向上. X轴 : 左右方向,向右是正值. Y轴 : 远近方向,远离你是负. Z轴 : 上下方向,向上是正值.

  6. 方法Equals和操作符==的区别

    http://www.codeproject.com/Articles/584128/What-is-the-difference-between-equalsequals-and-Eq When w ...

  7. mac下app store 无法完成您的购物操作

    最近在mac下使用app store 的时候出现提示:“我们无法完成您的购物操作 网络连接已中断”.但是我的网络是好的,图片如下: 网上找了各种解决办法,比如将DNS改成 114.114.114.11 ...

  8. POJ 1166 The Clocks (爆搜 || 高斯消元)

    题目链接 题意: 输入提供9个钟表的位置(钟表的位置只能是0点.3点.6点.9点,分别用0.1.2.3)表示.而题目又提供了9的步骤表示可以用来调正钟的位置,例如1 ABDE表示此步可以在第一.二.四 ...

  9. Android ContentProvider和Uri详解 (绝对全面)

        ContentProvider的基本概念 : 1.ContentProvider为存储和读取数据提供了统一的接口 2.使用ContentProvider,应用程序可以实现数据共享 3.andr ...

  10. 最大流 Dinic + Sap 模板

    不说别的,直接上模板. Dinic+当前弧优化: struct Edge{ int x,y,c,ne; }e[M*]; int be[N],all; int d[N],q[N]; int stack[ ...