最后两题是orzCJK学长帮忙代打的,不过总算是到蓝名了(上次睡迟了,只剩半个小时,结果作大死点开题目看,结果rating掉了100多),还有论代码风格的重要性!!!(没写空格被学长各种D)

A题

题目简意:

有两个人做游戏,每个人有一块电池,给定初始电量a,b,每一秒你可以给一块电池充1%的电,另一块电池就会掉2%的电,当有一个没电时游戏结束。求游戏的最长时间。

input
3 5
output
6
input
4 4
output
5

题解:

大概就是贪心吧,每次给电少的电池充电,注意细节(当有一个电池的电量少于2%时不能充电)。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> #ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif #ifdef CT
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif #define R register
#define getc() (S==T&&(T=(S=B)+fread(B,1,1<<15,stdin),S==T)?EOF:*S++)
#define gmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define gmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
char B[1<<15],*S=B,*T=B;
inline int FastIn()
{
R char ch;R int cnt=0;R bool minus=0;
while (ch=getc(),(ch < '0' || ch > '9') && ch != '-') ;
ch == '-' ?minus=1:cnt=ch-'0';
while (ch=getc(),ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
return minus?-cnt:cnt;
} int main()
{
R int a1=FastIn(),a2=FastIn(),ans=0;
while ((a1>1||a2>1)&&a1>0&&a2>0){
ans++;
a1>a2?(a1-=2,++a2):(a2-=2,++a1);
}
printf("%d\n",ans );
return 0;
}

B

题目简意:

给定一个序列,你可以任意排列,问排列后前一个数比后一个数大的个数的最大值。

input
5
20 30 10 50 40
output
4
input
4
200 100 100 200
output
2

题解:

我们可以转换一下思路,这题其实可以看做求数字出现次数的最大值,因为如果某个数出现的次数是最多的,那么这些数必然会被分在不同的组里(我们假装每个组都是又偏序关系的)。所以答案就是(N-出现最多的次数)。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> #ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif #ifdef CT
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif #define R register
#define getc() (S==T&&(T=(S=B)+fread(B,1,1<<15,stdin),S==T)?EOF:*S++)
#define gmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define gmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
char B[1<<15],*S=B,*T=B;
inline int FastIn()
{
R char ch;R int cnt=0;R bool minus=0;
while (ch=getc(),(ch < '0' || ch > '9') && ch != '-') ;
ch == '-' ?minus=1:cnt=ch-'0';
while (ch=getc(),ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
return minus?-cnt:cnt;
}
#define maxn 1010
int num[maxn];
int main()
{
R int n=FastIn(),maxx=0,x;
for (R int i=1;i<=n;i++)num[x=FastIn()]++,cmax(maxx,num[x]);
printf("%d\n",n-maxx );
return 0;
}

C

题目简意:

平面上给定N个点,求欧几里得距离和曼哈顿距离相等的点对个数。

input
3
1 1
7 5
1 5
output
2
input
6
0 0
0 1
0 2
-1 1
0 1
1 1
output
11

题解:

欧几里得距离和曼哈顿距离相等嘛。。。不就是在同一条平行于x轴或平行于y轴的直线上吗?排个序然后搞一搞就好啦~

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> #ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif #ifdef CT
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif #define R register
#define getc() (S==T&&(T=(S=B)+fread(B,1,1<<15,stdin),S==T)?EOF:*S++)
#define gmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define gmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
char B[1<<15],*S=B,*T=B;
inline int FastIn()
{
R char ch;R int cnt=0;R bool minus=0;
while (ch=getc(),(ch < '0' || ch > '9') && ch != '-') ;
ch == '-' ?minus=1:cnt=ch-'0';
while (ch=getc(),ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
return minus?-cnt:cnt;
}
#define maxn 200010
struct Poi
{
int x,y;
}p[maxn];
inline bool cmp1(const Poi &i,const Poi &j){
return i.x<j.x;
}
inline bool cmp2(const Poi &i,const Poi &j){
return i.y<j.y||(i.y==j.y&&i.x<j.x);
}
int main()
{
R int n=FastIn();R long long ans=0;
for (R int i=1;i<=n;i++){
p[i]=(Poi){FastIn(),FastIn()};
}
std::sort(p+1 ,p+n+1,cmp1);
R int cnt=0;
for (R int i=1;i<=n;i++){
if (i>1&&p[i].x==p[i-1].x)ans+=cnt++;
else cnt=1;
}
std::sort(p+1,p+n+1,cmp2);
cnt=0;
for (R int i=1;i<=n;i++){
if (i>1&&p[i].y==p[i-1].y)ans+=cnt++;
else cnt=1;
}
cnt=0;
for (R int i=1;i<=n;i++){
if (i>1&&p[i].x==p[i-1].x&&p[i].y==p[i-1].y) ans-=cnt++;
else cnt=1;
}
printf("%lld\n",ans );
return 0;
}

D

题目简意:

给定一个长度为N的字符串,‘w’代表需要旋转的,‘h’代表不需要旋转的,翻到下一张照片需要a秒,旋转需要b秒,看一张照片需要1s,求T秒内看的照片的最大数量。

input
4 2 3 10
wwhw
output
2
input
5 2 4 13
hhwhh
output
4
input
5 2 4 1000
hhwhh
output
5
input
3 1 100 10
whw
output
0

题解:

我们猜一个结论(雾),你枚举一个左端点,它右端点的变化是不降的。然后这个结论也很好脑补。然后就做完啦。。。

代码:

#include <bits/stdc++.h>
using namespace std; #define RG register
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0) #define maxn 1000010
char str[maxn];
int sum[maxn];
int n, a, b;
inline int cost(RG int l, RG int r)
{
RG int ans = sum[r] - sum[l - 1];
RG int L = (n + 1) - l;
RG int R = r - (n + 1);
RG int g = ans + a * dmin(L + L + R, L + R + R);
return g;
}
int main()
{
RG int T;
cin >> n >> a >> b >> T >> (str + 1);
for(RG int i = 1; i <= n; ++i) str[i + n] = str[i];
for(RG int i = 1; i <= (n << 1); ++i)
sum[i] = sum[i - 1] + (str[i] == 'w' ? b + 1 : 1);
RG int ans = 0;
RG int l = 2;
for(RG int r = n + 1; r <= (n << 1); ++r)
{
cmax(l, r - n + 1);
while(l <= n + 1 && cost(l, r) > T) ++l;
if(l > n + 1) break;
cmax(ans, r - l + 1);
}
cout << ans << endl;
}

E

题目简意:

给定一个N*M的矩阵,让你给出一种方案,使得原矩阵每一行和每一列的偏序关系不变,然后新矩阵的最大的数最小。

input
2 2
1 2
3 4
output
1 2
2 3
input
4 3
20 10 30
50 40 30
50 60 70
90 80 70
output
2 1 3
5 4 3
5 6 7
9 8 7

题解:

并查集+最长路。先用并查集把每一行/每一列的相同的数并起来,然后再建图,每个点只会向相邻的点连边,求这个点的最长路。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> #ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif #ifdef CT
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif #define R register
#define getc() (S==T&&(T=(S=B)+fread(B,1,1<<15,stdin),S==T)?EOF:*S++)
#define gmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define gmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
char B[1<<15],*S=B,*T=B;
inline int FastIn()
{
R char ch;R int cnt=0;R bool minus=0;
while (ch=getc(),(ch < '0' || ch > '9') && ch != '-') ;
ch == '-' ?minus=1:cnt=ch-'0';
while (ch=getc(),ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
return minus?-cnt:cnt;
}
#define maxn 1000010
#define maxe 2000010
#define pos(_i,_j) (((_i)-1)*m+(_j))
int last[maxn] , to[maxe] , next[maxe] , w[maxe] , val[maxn] , buff[maxn] , ecnt , dis[maxn] , Fa[maxn];
inline bool cmp(const int &i,const int &j) {
return val[i] < val[j];
}
inline int Find(R int x){return Fa[x]==x ? x : Fa[x] = Find(Fa[x]);}
#define add(_a,_b,_v) ( to[++ecnt] = (_b) , next[ecnt] = last[_a] , last[_a] = ecnt , w[ecnt] = (_v))
int dfs(R int x){
if (dis[x]) return dis[x];
R int tmp=1;
for (R int i=last[x];i;i=next[i])
cmax(tmp,dfs(Find(to[i]))+w[i]);
return dis[x] = tmp;
}
int main()
{
R int n = FastIn() , m = FastIn();
for (R int i = 1 ; i<=n ; i++)
for (R int j = 1 ; j<=m ; j++)
val[pos(i,j)] = FastIn() , Fa[pos(i,j)] = pos(i,j);
for (R int i = 1 ; i <= n ; i++)
{
for (R int j = 1 ; j<=m ; j++) buff[j] = pos(i,j);
std::sort ( buff+1 , buff+m+1 , cmp);
for (R int j=1;j<m;j++)
{
val[buff[j]]==val[buff[j+1]] ? Fa[Find(buff[j])] = Find (buff[j+1]) : 0;
}
}
for (R int j = 1 ; j<=m ; j++)
{
for (R int i = 1 ; i<=n ; i++) buff[i] = pos(i,j);
std::sort(buff+1 , buff+n+1 , cmp);
for (R int i = 1 ; i<n ; i++)
{
val[buff[i]]==val[buff[i+1]] ? Fa[Find(buff[i])] = Find (buff[i+1]) : 0;
}
}
for (R int i = 1 ; i<=n ; i++)
{
for (R int j = 1 ; j<=m ; j++) buff[j] = pos(i,j);
std::sort(buff+1 , buff+m+1 , cmp);
for (R int j = 1 ; j<m ; j++)
{
val[buff[j]]!=val[buff[j+1]] ? add(Find(buff[j+1]),Find(buff[j]),1) : 0;
}
}
for (R int j = 1 ; j<=m ; j++)
{
for (R int i = 1; i<=n ; i++) buff[i] = pos(i,j);
std::sort(buff+1 , buff+n+1 , cmp);
for (R int i = 1 ; i<n ; i++)
{
val[buff[i]]!=val[buff[i+1]] ? add(Find(buff[i+1]),Find(buff[i]),1) : 0;
}
}
for (R int i=1;i<=n*m;i++)
if (!dis[Find(i)])
dfs(Find(i));
for (R int i=1;i<=n;i++)
{
for (R int j=1;j<=m;j++)
printf("%d ",dis[Find(pos(i,j))]);
puts("");
}
return 0;
}

Codeforces Round #345 (Div 2)的更多相关文章

  1. Codeforces Round #581(Div. 2)

    Codeforces Round #581(Div. 2) CF 1204 A. BowWow and the Timetable 题解:发现,$4$的幂次的二进制就是一个$1$后面跟偶数个$0$. ...

  2. Codeforces Round #334(div.2)(新增不用二分代码) B

    B. More Cowbell time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  3. Codeforces Round #334(div.2) A

    A. Uncowed Forces time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. codeforces Round #389(Div.2)C Santa Claus and Robot(思维题)

    题目链接:http://codeforces.com/contest/752/problem/C 题意:给出一系列机器人的行动方向(机器人会走任意一条最短路径),问最少标记几个点能让机器人按这个 路径 ...

  5. Codeforces Round #626 (Div. 2) B. Count Subrectangles

    题目连接:https://codeforces.com/contest/1323/problem/B 题意:给一个大小为n的a数组,一个大小为m的b数组,c数组是二维数组c[i][j]=a[i]*b[ ...

  6. Codeforces Round #342 (Div 2) 解题报告

    除夕夜之有生之年CF第一场 下午从奶奶家回到姥姥家,一看还有些时间,先吃点水果陪姥姥姥爷聊了会儿,再一看表,5:20....woc已经开场20分钟了...于是抓紧时间乱搞.. **A. Guest F ...

  7. Codeforces Round 1153(div. 2)

    这场奇差.ABCD四题.179名. 但是E在现场有213个人做出. 描述一下我在35分钟做完D后的心路历程. 首先看到这道E,第一下想到的是把所有的横向和竖向的整列(行)求出相连的个数. 然后想如何能 ...

  8. Codeforces Round #622(Div 2)C2. Skyscrapers (hard version)

    题目链接 : C2. Skyscrapers (hard version) 题目描述 : 与上一道题类似,只是数据范围变大, 5e5, 如果用我们原来的方法,铁定是超时的. 考察点 : 单调栈,贪心, ...

  9. Codeforces Round #556(Div.1)

    A 容易发现i,i+1至少有一个数出现,于是可以让尽量多的2和奇数出现 #include<bits/stdc++.h> using namespace std; int n,s1,s2; ...

随机推荐

  1. static 和extern关键字

    static是C++中常用的修饰符,它被用来控制变量的存贮方式和可见性.extern "C"是使C++能够调用C写作的库文件的一个手段,如果要对编译器提示使用C的方式来处理函数的话 ...

  2. $APIO~2019$ 游记

    我是鸽子. Upd:我全国倒数第一稳了. Uupd:时间过去好久了,这段时间发生很多事,比如NOIP没了... APIO时候的事也记得不是很清楚了,随便写点颓废资料吧: 如果想吃离酒店最近的一家火锅店 ...

  3. QtSpim使用Tips

    QtSpim使用记录 垃圾QtSpim,输入中文会死机 MIPS的中文资料奇缺,如果有问题建议google参考英文资料,许多外国大学的网站上有对MIPS各方面的详细介绍 QtSpim是MIPS处理器的 ...

  4. eclipse中web项目tomcat的设置

    1.  出现的问题: web开发中(eclipse环境),为本地项目添加tomcat,我们一般都会选择直接添加.在本次开发中突然遇到一个问题:因为项目涉及到文件上传,我利用MultipartFile进 ...

  5. MySQL第三讲 一一一一 视图、触发器、函数、存储过程

    1. 视图 1.1 视图前戏 我们之前讲有,临时表的概念. 现在我们创建一个临时表:select * from (select * from tb1 where id between 10 and 1 ...

  6. 脚本_通过进程与端口判断myslq服务

    #!bin/bashif [[ $port -eq 1 || $porcess -eq 2 ]];then  #通过条件判断端口和进程执行的返回值.     echo "mysql is s ...

  7. static静态和非静态详解

    static 作为Java中的一个关键字,用于修饰方法.成员变量(Field),统称为成员. 有static修饰的成员   属于类 1.方法称为静态方法(类方法),Field称为类的属性. 2.静态成 ...

  8. VM错误解决:This Virtual Machine Appears To Be In Use

    刚才准备做网站(数据备份都在VM里面),没想到启动不起来,咋一看,出现This Virtual Machine Appears To Be In Use字号,不过貌似我没有启动任何VM啊,何来in u ...

  9. node模块管理

    淘宝镜像:npm install -g cnpm --registry=https://registry.npm.taobao.org

  10. crontab定时执行shell脚本

    步骤一    首先我们先看一下是否安装了crontab.一般情况下linux系统会自带crontab及crond.如果没有安装,请使用以下指令安装:yum install vixie-cron     ...