感觉自己有点强迫症  不都写出来就找理由不写题解

http://codeforces.com/contest/1015   题目链接

A. Points in Segments

题目意思  n个线段 去覆盖1-m 中的点 问你没有覆盖的点的个数和位置

这个数据很小,可以直接暴力查找

思考:如果n<1e6, m<=1e8 呢?

#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e5+;
const int INF=0x3f3f3f3f;
map<int,int> mp;
int32_t main()
{
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++)
{
int a,b; cin>>a>>b;
for(int j=a;j<=b;j++)
mp[j]=;
}
int t=;
for(int i=;i<=m;i++)
{
if(mp[i]==)
{
t++;
}
}cout<<t<<endl;
for(int i=;i<=m;i++)
{
if(mp[i]==)
{
cout<<i<<" ";
}
}
}

A.cpp

如果 m<=1e8的 话,可以标记 线段的起点 重点后一位     左右搜一遍

如1-5   a[1]=1; a[6]=-1;

B. Obtaining the String

一个n,两个字符串(ss,tt),左右移动前一个字符串 使两个字符串相等  求最小移动次数;

对比 ss ,tt 当ss[i] !=tt[i]; 在ss[i]后面找和tt[i]一样的, 移动到ss[i];没有就输出-1;

#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e5+;
const int INF=0x3f3f3f3f;
map<int,int> mp;
vector<int> pp;
int32_t main()
{
int n; cin>>n;
string ss,tt; cin>>ss; cin>>tt;
//if(ss==tt) { cout<<-1<<endl; return 0;}
int j=;
for(int i=;i<n;i++)
{
if(ss[j]==tt[i])
{
j++; continue;
}
int t=;
for(int k=j+;k<n;k++)
{ if(ss[k]==tt[i])
{
for(int x=k-;x>=j;x--)
{
swap(ss[x],ss[x+]);
t=;
pp.push_back(x+);
}
if(t==) { j++;break;}
}
}
if(t==) { cout<<-<<endl; return ;}
}
cout<<pp.size()<<endl;
for(int i=;i<pp.size();i++)
{
cout<<pp[i]<<" ";
}
}

B.cpp

C. Songs Compression

n 组数据 一开始的歌曲数据大小  压缩后的数据大小, 要是数据小于等于m;

直接计算一开始的大小,每次减去 差值最大的;看多少次后数据小于等于m; 压缩不到m就输出-1;

#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e5+;
const int INF=0x3f3f3f3f;
int a[maxn];
int b[maxn];
int d[maxn];
int32_t main()
{
int n,m; cin>>n>>m; int ans1=; int ans2=;
for(int i=;i<=n;i++)
{
cin>>a[i]>>b[i];
d[i]=a[i]-b[i];
ans1+=a[i];
ans2+=b[i];
}
if(ans2>m) { cout<<-<<endl;return ;}
//if(ans1<=m) { cout<<0<<endl;return 0;}
sort(d+,d++n); int t=;
for(int i=n;i>=;i--)
{
if(ans1<=m) break;
ans1=ans1-d[i];
t++;
}
cout<<t<<endl;
}

C.cpp

D. Walking Between Houses

在1-n 中走 k次(随你走到哪,不能不走) 使走的路程为 s;

在保证每次都至少走一步的情况下 先走最大的 1 - n- 1 - n -1 -n....;

最后再每次走一步;

10 9 45 来说 每次走的距离为 9 9 9 9 5 1 1 1 1;

#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e5+;
const int INF=0x3f3f3f3f;
int32_t main()
{
int n,k,s; cin>>n>>k>>s;
if(s>(n-)*k||s<k) { cout<<"NO"<<endl; return ;}
cout<<"YES"<<endl;
int t=;
while(s)
{
if(s-n+>=k-)
{
if(t%==) cout<<n<<" ";
else cout<<<<" ";
t++;
k--;
s=s-(n-); //cout<<s<<endl;
}
else
{
int d=s-(k-);// cout<<d<<endl;
int pos=;
if(t%==) { cout<<+d<<" "; pos=+d; }
else { cout<<n-d<<" "; pos=n-d;}
t++;
k--;
int x=;
while(k)
{
if(x%==)
{
if(pos->=) cout<<pos-<<" ";
else cout<<pos+<<" ";
}
else cout<<pos<<" ";
k--;
x++;
}
break;
}
}
}

D.cpp

E1. Stars Drawing (Easy Edition)

可以直接暴力搜  找到一个点  直接往上下左右搜  看照射的距离  大于1就全部标记

#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
pair<int,int> pos[]={ {,},{,-},{,},{-,} };
bool tf[][];
char a[][];
int x2[];
int x1[];
int x3[];
int32_t main()
{
int n,m; cin>>n>>m; getchar();
for(int i=;i<n;i++)
gets(a[i]);
int t=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(a[i][j]=='*')
{
//cout<<i<<" "<<j<<endl;
int z=;
while()
{
int x=;
for(int k=;k<;k++)
{
int x1=i+z*pos[k].first;
int y1=j+z*pos[k].second;
if(x1<||x1>=n||y1<||y1>=m)
{
continue;
}
if(a[x1][y1]=='*')
{
x++;
} }
//cout<<x<<endl;
if(x==)
{
tf[i][j]=;
for(int k=;k<;k++)
{
int x1=i+z*pos[k].first;
int y1=j+z*pos[k].second;
if(x1<||x1>=n||y1<||y1>=m)
{
continue;
}
if(a[x1][y1]=='*')
{
tf[x1][y1]=;
} }
}
else break;
z++;
}
if(z==) continue;
else
{
x1[t]=i;
x2[t]=j;
x3[t]=z-; t++;
}
}
}
} // cout<<t<<endl;
int k1=;
int k2=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(a[i][j]=='*') k1++;
if(tf[i][j]==) k2++;
}
}
if(k1!=k2) cout<<-<<endl;
else
{
cout<<t<<endl;
for(int i=;i<t;i++)
{
cout<<x1[i]+<<" "<<x2[i]+<<" "<<x3[i]<<endl;
}
} //cout<<k1<<" "<<k2<<endl;
}

E1.cpp

E2. Stars Drawing (Hard Edition)

先预处理 每个点 上下左右 可以照射的距离   再标记

预处理有些技巧 ,不能暴力搜  要找相邻两个点的关系

由于预处理 和 标记 分开  不会超时;

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+;
int l[maxn][maxn];
int r[maxn][maxn];
int u[maxn][maxn];
int d[maxn][maxn];
int ans1[maxn*maxn];
int ans2[maxn*maxn];
int ans3[maxn*maxn];
char a[maxn][maxn];
bool f[maxn][maxn];
int main()
{
int n,m;
cin >> n >> m;
int i,j,s,y;
for (i = ; i <= n; i++)
for (j = ; j <= m; j++) cin >> a[i][j];
for (i = ; i <= n; i++) for (j = ; j <= m; j++)
if (a[i][j] == '*') l[i][j] = l[i][j-] + ; else l[i][j] = ; for (i = ; i <= n; i++) for (j = m; j >= ; j--)
if (a[i][j] == '*') r[i][j] = r[i][j+] + ; else r[i][j] = ; for (j = ; j <= m; j++) for (i = ; i <= n; i++)
if (a[i][j] == '*') u[i][j] = u[i-][j] + ; else u[i][j] = ; for (j = m; j >= ; j--) for (i = n; i >= ; i--)
if (a[i][j] == '*') d[i][j] = d[i+][j] + ; else d[i][j] = ; int t=;
for (i = ; i <= n; i++)
for (j = ; j <= m; j++) if (a[i][j] == '*') {
s = min(min(r[i][j+],l[i][j-]),min(u[i-][j],d[i+][j]));
if (s > ) {
ans1[t]=i; ans2[t]=j; ans3[t]=s; t++; for (y = j-s; y <= j+s; y++) f[i][y] = ;
for (y = i-s; y <= i+s; y++) f[y][j] = ;
}
}
for (i = ; i <= n; i++) for (j = ; j <= m; j++)
if (a[i][j] == '*' && f[i][j] == ) {
cout << - << endl;
return ;
}
cout<<t-<<endl;
for(int i=;i<=t-;i++)
cout<<ans1[i]<<" "<<ans2[i]<<" "<<ans3[i]<<endl;
}

E2.cpp

Codeforces Div3 #501 A-E(2) F以后补的更多相关文章

  1. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  2. Codeforces Round #598 (Div. 3) A,B,C,D{E,F待补}

    A. Payment Without Change   #include<bits/stdc++.h> using namespace std; #define int long long ...

  3. Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]

    hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...

  4. Codeforces Round #541 (Div. 2) (A~F)

    目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...

  5. Codeforces Round #519 by Botan Investments F. Make It One

    https://codeforces.com/contest/1043/problem/F 题意 给你n个数,求一个最小集合,这个集合里面数的最大公因数等于1 1<=n<=3e5 1< ...

  6. Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)

    F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...

  7. Codeforces Round #590 (Div. 3)(e、f待补

    https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again #include<bits/stdc++.h> ...

  8. Codeforces Round #600 (Div. 2)E F

    题:https://codeforces.com/contest/1253/problem/E 题意:给定n个信号源,俩个参数x和s,x代表这个信号源的位置,s代表这个信号源的波及长度,即这个信号源可 ...

  9. Codeforces Round #346 (Div. 2) E F

    因为很久没有个人认真做题了 昨天晚上开了场虚拟cf来锻炼个人手速 选的是第一次做cf的场 那时候7出3还被hack...之后也没补题 这次做的时候顺便回忆了一下以前比赛的时候是怎么想的 发现经验还是很 ...

随机推荐

  1. 尚学堂java 答案解析 第四章

    本答案为本人个人编辑,仅供参考,如果读者发现,请私信本人或在下方评论,提醒本人修改 一.选择题 1.BD 解析:B:类必须有构造方法,若程序未写,这系统自动调用系统构造方法. D:super()会调用 ...

  2. 一款c语言实现的赛车游戏

    博主学习c语言已经有一段时间了,出于对自己学习检验的目的,自制了一款c语言赛车游戏. 由于本质是检验和尝试,所以并没有注重游戏的界面.下文是开发文档,在博主的github网页可以下载源码,注意本项目使 ...

  3. oo作业总结(一)

    概述 经历了三次oo作业的洗礼,让我对java语言的强大以及面向对象编程有了初步的理解(当然,我是小白).本文接下来就将对自己这三次作业的代码进行分析以及分享自己的心路历程. 基础知识点考核 针对前三 ...

  4. 【原创】<Debug> not positioned on a valid record

    [Problem] QSqlQuery::value: not positioned on a valid record QSqlQuery :: value:未定位在有效记录上 [Solution] ...

  5. 【转】C语言中字符串输入的三种方法

    在网上看到,讲的还算详细,转过来学习一下...... ======================================================================= 使 ...

  6. angular4-事件绑定

    事件绑定语法(可以通过 (事件名) 的语法,实现事件绑定) <date-picker (dateChanged)="statement()"></date-pic ...

  7. 深入理解java虚拟机---对象的访问定位(十)

    引用其他人的文章: https://www.cnblogs.com/YYfish/p/6722258.html 那是怎么访问对象呢? java 程序是通过栈上的reference数据来操作堆上的具体对 ...

  8. tomcat的安装及配置

    1.首先进tomcat官网下载zip压缩文件:http://tomcat.apache.org/download-90.cgi 2.解压缩到指定文件压(后面配置环境变量会用到) 3.配置环境变量 4. ...

  9. 记录搭建ssm项目

    搞java也快3年了,搭建一个ssm居然有点吃力. 参考链接:https://blog.csdn.net/gebitan505/article/details/44455235/ 环境准备:jdk8. ...

  10. powerdesigner导出sql时报错 Generation aborted due to errors detected during the verification of the model.

    powerdesigner导出sql时报错 Generation aborted due to errors detected during the verification of the model ...