标签:
思路:先把所有的线段投影到x轴,然后将所有线段的起末坐标存进数组,排序后从坐标最小开始枚举。如果遇到起点标志,就加一;结束点标志减一。如此即可求出同一时刻,遇到当前线段结束点时,有多少线段包含在内
/************************************************************** Problem:hdu 5417 User: youmi Language: C++ Result: Accepted Time:1591MS Memory:1816K ****************************************************************/ //#pragma comment(linker, "/STACK:1024000000,1024000000") //#include<bits/stdc++.h> #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <map> #include <stack> #include <set> #include <sstream> #include <cmath> #include <queue> #include <deque> #include <string> #include <vector> #define zeros(a) memset(a,0,sizeof(a)) #define ones(a) memset(a,-1,sizeof(a)) #define sc(a) scanf("%d",&a) #define sc2(a,b) scanf("%d%d",&a,&b) #define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c) #define scs(a) scanf("%s",a) #define sclld(a) scanf("%I64d",&a) #define pt(a) printf("%d\n",a) #define ptlld(a) printf("%I64d\n",a) #define rep(i,from,to) for(int i=from;i<=to;i++) #define irep(i,to,from) for(int i=to;i>=from;i--) #define Max(a,b) ((a)>(b)?(a):(b)) #define Min(a,b) ((a)<(b)?(a):(b)) #define lson (step<<1) #define rson (lson+1) #define eps 1e-6 #define oo 0x3fffffff #define TEST cout<<"*************************"<<endl const double pi=4*atan(1.0); using namespace std; typedef long long ll; inline int read() { int x=0,f=1; char ch=getchar(); while (ch<‘0‘||ch>‘9‘) {if (ch==‘-‘) f=-1; ch=getchar();} while (ch>=‘0‘&&ch<=‘9‘) {x=x*10+ch-‘0‘; ch=getchar();} return x*f; } const int maxn=20000+10; int n,cnt,x,y,z,d,po,lmax,l,r,ans; struct data { int x,y,z; }a[maxn]; bool cmp(data a,data b) { if (a.x!=b.x) return a.x<b.x; else { if (a.y!=b.y) return a.y<b.y; else return a.z<b.z; } } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif int T_T; scanf("%d",&T_T); for(int kase=1;kase<=T_T;kase++) { n=read(); cnt=0; for (int i=1;i<=n;i++) { x=read(),y=read(),z=read(),d=read(); if (y-x<=2*z) { if (d==1) po=0; else po=1; a[++cnt].x=y-z; a[cnt].y=0; a[cnt].z=po; a[++cnt].x=x+z; a[cnt].y=1; a[cnt].z=po; } } sort(a+1,a+cnt+1,cmp); lmax=l=r=ans=0; for (int i=1;i<=cnt;i++) { if (a[i].z==0) { if (a[i].y==0) ++l; else --l; } else { if (a[i].y==0) ++r; else --r; } if (l>lmax) lmax=l; if (lmax+r>ans) ans=lmax+r; } printf("Case #%d:\n%d\n",kase,ans); } return 0; }
2016"百度之星" - 初赛(Astar Round2A)
1001 ALL X
思路:x*(10n-1)/9,之后的应该就简单了
1002 Sitting in Line
这个已经再博客里写过了,所以把标题已经连接到写的那个博客了
思路:
1---B
2---BBD
3---BBD|B|BDD
4---BBD|B|BDD|B|BBD|D|BDD
5---BBD|B|BDD|B|BBD|D|BDD|B|BBD|B|BDD|D|BBD|D|BDD
从第五行可看出规律:每8个为一组,其中BBD,BDD连续重复;4的倍数上对应的字母,又是题给规律的出现,那么这部分进行dfs即可;然后对于小于等于8的部分,可以用一个数组预处理。
注意:(小于等于8的部分)与(4的倍数)在位置为4的地方重复计算了一次,所以要去掉这一部分
/************************************************************** Problem:hdu 5694 User: youmi Language: C++ Result: Accepted Time:0MS Memory:1572K ****************************************************************/ //#pragma comment(linker, "/STACK:1024000000,1024000000") //#include<bits/stdc++.h> #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <map> #include <stack> #include <set> #include <sstream> #include <cmath> #include <queue> #include <deque> #include <string> #include <vector> #define zeros(a) memset(a,0,sizeof(a)) #define ones(a) memset(a,-1,sizeof(a)) #define sc(a) scanf("%d",&a) #define sc2(a,b) scanf("%d%d",&a,&b) #define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c) #define scs(a) scanf("%s",a) #define sclld(a) scanf("%I64d",&a) #define pt(a) printf("%d\n",a) #define ptlld(a) printf("%I64d\n",a) #define rep(i,from,to) for(int i=from;i<=to;i++) #define irep(i,to,from) for(int i=to;i>=from;i--) #define Max(a,b) ((a)>(b)?(a):(b)) #define Min(a,b) ((a)<(b)?(a):(b)) #define lson (step<<1) #define rson (lson+1) #define eps 1e-6 #define oo 0x3fffffff #define TEST cout<<"*************************"<<endl const double pi=4*atan(1.0); using namespace std; typedef long long ll; inline ll read() { ll x=0,f=1; char ch=getchar(); while (ch<‘0‘||ch>‘9‘) {if (ch==‘-‘) f=-1; ch=getchar();} while (ch>=‘0‘&&ch<=‘9‘) {x=x*10+ch-‘0‘; ch=getchar();} return x*f; } int b[]={0,1,2,2,0,3,3,3,0}; ll sovle(ll tt) { if(tt==0) return 0; ll ans=0; ans+=sovle(tt/4); if(tt<4) return b[tt]; else if(tt<8) { if(tt==4) return ans+b[3]; else return ans+b[tt]; } ans+=3*(tt/8); ans+=sovle(tt%8); if(tt%8>=4) ans-=1; return ans; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif int T_T; scanf("%d",&T_T); for(int kase=1;kase<=T_T;kase++) { ll l,r; l=read(),r=read(); ll ans=sovle(r); ans-=sovle(l-1); ptlld(ans); } }
1006 Gym Class
这个也在01动态规划里的第一题已经总结过了,所以这里也直接把链接给到相应博客了
标签:
原文地址:http://www.cnblogs.com/youmi/p/5576111.html