[BestCoder] Round #36
来源:互联网 发布:nginx http2.0 配置 编辑:程序博客网 时间:2024/05/29 14:26
题目地址 http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=574
1001
首先判断长度能不能被3整除,然后字符串分成三段看每段的字母是否相同,再判断一下三段的字符是否各不相同。
#define rd(x) scanf("%d",&x)#define rd2(x,y) scanf("%d%d",&x,&y)#define rd3(x,y,z) scanf("%d%d%d",&x,&y,&z)using namespace std;typedef long long ll;string str;int main(){ while(cin>>str) { int len=str.length(); bool ok=1; if(len<3||len%3!=0) { ok=0; cout<<"NO"<<endl; continue; } int ge=len/3; char a,b,c; a=str[0]; b=str[ge]; c=str[2*ge]; for(int i=1;i<ge;i++) { if(str[i]!=str[i-1]) { ok=0; } } for(int i=ge+1;i<2*ge;i++) { if(str[i]!=str[i-1]) ok=0; } for(int i=2*ge+1;i<3*ge;i++) if(str[i]!=str[i-1]) ok=0; if(ok&&a!=b&&a!=c&&b!=c) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
1002
用map<int,int>保存高度为H的树有多少个,然后对应输出就可以了,注意每次输出后该高度的树数目清0.
输入用到了快速读入。
#define rd(x) scanf("%d",&x)#define rd2(x,y) scanf("%d%d",&x,&y)#define rd3(x,y,z) scanf("%d%d%d",&x,&y,&z)using namespace std;typedef long long ll;const int maxn=1000100;map<int,int>mp;inline int read(){ char ch=getchar();int x=0,f=1; while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();} while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();} return x*f;}int n,m;int main(){ while(rd2(n,m)!=EOF) { mp.clear(); int x; for(int i=1;i<=n;i++) { x=read(); mp[x]++; } for(int i=1;i<=m;i++) { x=read(); printf("%d\n",mp[x]); mp[x]=0; } } return 0;}
1003
根据大神的思路写的,离线,首先把树按高度从大到小排好序,然后把查询按查询的高度从大到小排序,然后对于每次查询,从大到小去种树,因为前面已经排好序了,所以遍历就可以了,每次查询只要树的高度大于查询的高度就一直种树,初始块为0,当种第i棵树时,如果它的两边都为空,那么块+1,如果它的两边都不空,那么块-1.思路膜拜。
#define rd(x) scanf("%d",&x)#define rd2(x,y) scanf("%d%d",&x,&y)#define rd3(x,y,z) scanf("%d%d%d",&x,&y,&z)using namespace std;typedef long long ll;const int maxn=50010;struct query{ int id; int ans; int q;}Q[maxn];struct Tree{ int id; int high;}tree[maxn];bool cmp1(Tree a,Tree b){ if(a.high>b.high) return true; return false;}bool cmp2(query a ,query b){ if(a.q>b.q) return true; return false;}int n,q;bool has[maxn];bool cmp3(query a,query b){ if(a.id<b.id) return true; return false;}int main(){ while(rd2(n,q)!=EOF) { for(int i=1;i<=n;i++) { rd(tree[i].high); tree[i].id=i; } sort(tree+1,tree+1+n,cmp1); memset(has,0,sizeof(has)); for(int i=0;i<q;i++) { Q[i].id=i; rd(Q[i].q); } sort(Q,Q+q,cmp2); int cnt=0; int r=1; for(int i=0;i<q;i++) { if(i>0&&Q[i].q==Q[i-1].q) { Q[i].ans=Q[i-1].ans; continue; } while(tree[r].high>Q[i].q&&r<=n) { if(!has[tree[r].id-1]&&!has[tree[r].id+1]) { cnt++; has[tree[r].id]=1; } if(has[tree[r].id-1]&&has[tree[r].id+1]) { has[tree[r].id]=1; cnt--; } has[tree[r].id]=1; r++; } Q[i].ans=cnt; } sort(Q,Q+q,cmp3); for(int i=0;i<q;i++) { printf("%d\n",Q[i].ans); } } return 0;}
0 0
- [BestCoder] Round #36
- BestCoder Round #36
- BestCoder Round #36(Gunner-hash)
- BestCoder Round #36 HDU 5199 Gunner
- BestCoder Round #36 HDU(5198 - 5201)
- BestCoder Round #36(Strange Class-模拟)
- BestCoder Round #36(Trees-离线处理询问)
- BestCoder Round #3 BestCoder Sequence
- bestcoder round #1
- BestCoder round #1
- BestCoder Round #1
- 【索引】BestCoder Round #2
- BestCoder Round #2
- 【索引】BestCoder Round #3
- BestCoder Round #3
- BestCoder Round #3 小记
- BestCoder Round #4 题解
- BestCoder Round #6
- 安装win7、Ubuntu14.1双系统
- 背包问题总结
- 人民币大写
- 算法导论—堆排序(python)
- Windows下lex 与 yacc的使用(2)
- [BestCoder] Round #36
- uint8_t是什么类型
- JAVA
- matlab中图像数据类型转换
- PropertyDescriptor的使用
- java 非阻塞算法在并发容器中的实现(ConcurrentLinkedQueue源码)
- MATLAB中从文件夹批量读取图片文件的方法
- ELF去壳
- 种橇家记撬尘撂瓜读踩邓短尘尘道