Codeforces Div3 #501 A-E(2) F以后补
感觉自己有点强迫症 不都写出来就找理由不写题解
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以后补的更多相关文章
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- 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 ...
- Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]
hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...
- Codeforces Round #541 (Div. 2) (A~F)
目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...
- Codeforces Round #519 by Botan Investments F. Make It One
https://codeforces.com/contest/1043/problem/F 题意 给你n个数,求一个最小集合,这个集合里面数的最大公因数等于1 1<=n<=3e5 1< ...
- Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)
F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...
- Codeforces Round #590 (Div. 3)(e、f待补
https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again #include<bits/stdc++.h> ...
- Codeforces Round #600 (Div. 2)E F
题:https://codeforces.com/contest/1253/problem/E 题意:给定n个信号源,俩个参数x和s,x代表这个信号源的位置,s代表这个信号源的波及长度,即这个信号源可 ...
- Codeforces Round #346 (Div. 2) E F
因为很久没有个人认真做题了 昨天晚上开了场虚拟cf来锻炼个人手速 选的是第一次做cf的场 那时候7出3还被hack...之后也没补题 这次做的时候顺便回忆了一下以前比赛的时候是怎么想的 发现经验还是很 ...
随机推荐
- 阿里云免费申请https证书
申请地址 https://common-buy.aliyun.com/?spm=a2c4e.11153940.blogcont65199.22.30f968210RsUSx&commodi ...
- QuickStart系列:docker部署之MariaDB
Centos7里面没有Mysql 取而代之的是MariaDB,MariaDB是完全开源的.MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的 ...
- Ubuntu 16.04 中安装谷歌 Chrome 浏览器
http://jingyan.baidu.com/article/335530da98061b19cb41c31d.html 根据教程安装成功!! http://askubuntu.com/quest ...
- unity中鼠标按下加速漫游,鼠标抬起减速漫游。
private bool IsMouseUpOrDown=true; //一开始默认是鼠标抬起状态 if (Input.GetMouseButtonDown(1)) //鼠标按下的瞬间状态 { IsM ...
- vue安装与配置
直接引入 <script src="https://unpkg.com/vue"></script> 用npm安装 $ npm install vue ...
- Python自学笔记-装饰器1(廖雪峰的网站)
由于函数也是一个对象,而且函数对象可以被赋值给变量,所以,通过变量也能调用该函数. >>> def now(): ... print('2015-3-25') ... >> ...
- Unicode与中文转换工具类方法(转)
/* * 中文转unicode编码 */ public static String gbEncoding(final String gbString) { char[] utfBytes = gbSt ...
- WinPcap是用于网络封包抓取的一套工具
WinPcap是用于网络封包抓取的一套工具,可适用于32位的操作平台上解析网络封包,包含了核心的封包过滤,一个底层动态链接库,和一个高层系统函数库,及可用来直接存取封包的应用程序界面. Winpcap ...
- Python爬虫框架Scrapy实例(三)数据存储到MongoDB
Python爬虫框架Scrapy实例(三)数据存储到MongoDB任务目标:爬取豆瓣电影top250,将数据存储到MongoDB中. items.py文件复制代码# -*- coding: utf-8 ...
- JAVA自动补全代码
打开eclipse(对myeclipse同样适用) 找到窗口(windows)菜单,打开最后一项首选项(Preferences)找到下属菜单java打开,打开里边的编辑器(Editor)菜单,点击内容 ...