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中的String命令

    一.介绍 字符串是 Tcl 中的基本数据类型,所以有大量的字符串操作命令.一个比较重要的问题就是模式匹配,通过模式匹配将字符串与指定的模式(格式)相匹配来进行字符串的比较.搜索等操作. 二.strin ...

  2. iOS 开发中遇到的问题

    1. 关于纠结很久的KVO崩溃问题,其真正原因是,在删除roomItem的KVO之前,将这个对象已经赋值为nil,所以实际上并没有删除他的observer,因此而崩溃:长时间纠结的原因是受.cxx_d ...

  3. HTTP响应消息code解释

    常见HTTP状态(304,200等) 在网站建设的实际应用中,容易出现很多小小的失误,就像mysql当初优化不到位,影响整体网站的浏览效果一样,其实,网站的常规http状态码的表现也是一样,Googl ...

  4. 关于Linux的windows目录的挂载

    今天,linux主机下面要增加一点空间,不想再增加硬盘,所以就在实体机里面就设置了目录共享,添加自己系统的默认账号(为了增加自己主机的安全性,我都是设置的含有标点符号的密码---这也是这次挂载不成功的 ...

  5. 通知角标(2)只用一个TextView实现

    可以只用一个TextView实现通知角标,TextView的setCompoundDrawables函数可以在TextView的上,下,左,右,4条边处分别指定一个图片.见图1: 这个图片如果在角上, ...

  6. 传感器(2)常用api简介及列出当前设备支持的传感器代码

    Android SDK提供了Android sensor framework,可以用来访问当前Android设备内置的传感器. ASF提供了很多类和接口,可以帮助我们完成各种与传感器有关的任务. 例如 ...

  7. C# WinForm窗体 控件Control 的 Invalidate、Update、Refresh的区别

    Control.Refresh - does an Control.Invalidate followed by Control.Update.Refresh: 强制控件使其工作区无效并立即重绘自己和 ...

  8. ruby安装插件报错

    有时候我们需要安装ruby插件的时候,会报如下错误:  ERROR: Could not find a valid gem 'rdiscount' (>= 0), here is why: Un ...

  9. poj 3790 Recursively Palindromic Partitions (递推)

    题目 题意:求输入的数字的递归回文. 思路:答案等于这个数字一半之前的所有的 之和. #include <iostream> #include <cstdio> #includ ...

  10. BZOJ2299: [HAOI2011]向量

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2299 题解:乱搞就可以了... 不妨认为有用的只有(a,b)(a,-b)(b,a)(b,-a) ...