BZOJ 4747-4749题解 Usaco2016 Dec
来源:互联网 发布:淘宝仓库打包员辛苦吗 编辑:程序博客网 时间:2024/06/07 00:59
BZOJ 4747: [Usaco2016 Dec]Counting Haybales
给出N(1≤N≤100,000)个数,和 Q(1≤Q≤100,000)个询问。每个询问包含两个整数A,B(0≤A≤B≤1,000,00
0,000)。对于每个询问,给出数值在A到B间的数有多少个(包含A与B)。
暴力
#include<bits/stdc++.h> using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (o<<1)#define Rson ((o<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,0x3f,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define MEMx(a,b) memset(a,b,sizeof(a));#define INF (0x3f3f3f3f)#define F (1000000007)#define pb push_back#define mp make_pair#define fi first#define se second#define vi vector<int> #define pi pair<int,int>#define SI(a) ((a).size())#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;#define PRi2D(a,n,m) For(i,n) { \ For(j,m-1) cout<<a[i][j]<<' ';\ cout<<a[i][m]<<endl; \ } #pragma comment(linker, "/STACK:102400000,102400000")#define ALL(x) (x).begin(),(x).end()typedef long long ll;typedef long double ld;typedef unsigned long long ull;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return ((a-b)%F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}inline int read(){ int x=0,f=1; char ch=getchar(); while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();} while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();} return x*f;} #define MAXN (123456)int a[MAXN];int main(){// freopen("bzoj4747.in","r",stdin);// freopen(".out","w",stdout); int n=read(),q=read(); For(i,n) a[i]=read(); sort(a+1,a+1+n); For(i,q) { int p1=read(),p2=read(); int c=upper_bound(a+1,a+1+n,p1-1)-a; int d=upper_bound(a+1,a+1+n,p2)-a-1; printf("%d\n",d-c+1); } return 0;}
BZOJ 4748: [Usaco2016 Dec]Cities and States
依次给出N(1≤N≤200,000)个城市名及其州的代码(州代码保证仅有两位)。我们说,两个城市是一个“特殊对
”,如果他们来自不同的州且A城市的州代码是B城市的城市名首两位,B城市的州代码是A城市的城市名首两位。问
:在给定的信息中有多少个“特殊对”?
hash后暴力统计
#include<bits/stdc++.h> using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (o<<1)#define Rson ((o<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,0x3f,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define MEMx(a,b) memset(a,b,sizeof(a));#define INF (0x3f3f3f3f)#define F (1000000007)#define pb push_back#define mp make_pair#define fi first#define se second#define vi vector<int> #define pi pair<int,int>#define SI(a) ((a).size())#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;#define PRi2D(a,n,m) For(i,n) { \ For(j,m-1) cout<<a[i][j]<<' ';\ cout<<a[i][m]<<endl; \ } #pragma comment(linker, "/STACK:102400000,102400000")#define ALL(x) (x).begin(),(x).end()typedef long long ll;typedef long double ld;typedef unsigned long long ull;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return ((a-b)%F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}inline int read(){ int x=0,f=1; char ch=getchar(); while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();} while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();} return x*f;} map<pi ,int> h; map<pi ,int>::iterator it; int main(){// freopen("bzoj4748.in","r",stdin);// freopen(".out","w",stdout); int n=read(); For(i,n) { char s[100],s2[100]; scanf("%s%s",s,s2); int p1=(s[0]-'A')*233+s[1]-'A'; int p2=(s2[0]-'A')*233+s2[1]-'A'; if (h.count(mp(p1,p2))) h[mp(p1,p2)]++; else h[mp(p1,p2)]=1; } ll ans=0; for(it=h.begin();it!=h.end();it++) { pair<pi ,int> p=*it; pi pa=p.fi; swap(pa.fi,pa.se); if (h.count(pa)) { if (pa.fi<pa.se) ans+=h[pa]*(ll)p.se; } } printf("%lld\n",ans); return 0;}
BZOJ 4749: [Usaco2016 Dec]Moocast
每头牛手上有一台对讲机,给出N(1≤N≤200)头牛的坐标(X,Y)及其对讲机的极限传输半径P,也就是说该对讲
机能将信息传送到与之距离不超过P的对讲机。幸运的是,牛可以传递消息通过其他牛,所以没有必要每头牛能直接
传送到其他牛。请帮助奶牛确定:如果源于一头牛,最多能将信息传递到多少头牛?
暴力建图bfs
#include<bits/stdc++.h> using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (o<<1)#define Rson ((o<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,0x3f,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define MEMx(a,b) memset(a,b,sizeof(a));#define INF (0x3f3f3f3f)#define F (1000000007)#define pb push_back#define mp make_pair#define fi first#define se second#define vi vector<int> #define pi pair<int,int>#define SI(a) ((a).size())#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;#define PRi2D(a,n,m) For(i,n) { \ For(j,m-1) cout<<a[i][j]<<' ';\ cout<<a[i][m]<<endl; \ } #pragma comment(linker, "/STACK:102400000,102400000")#define ALL(x) (x).begin(),(x).end()typedef long long ll;typedef long double ld;typedef unsigned long long ull;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return ((a-b)%F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}inline int read(){ int x=0,f=1; char ch=getchar(); while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();} while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();} return x*f;} #define MAXN (300)vi edges[MAXN];ll n,x[MAXN],y[MAXN],p[MAXN];bool b[MAXN];int main(){// freopen("bzoj4749.in","r",stdin);// freopen(".out","w",stdout); n=read(); For(i,n) { x[i]=read(),y[i]=read(),p[i]=read(); } For(i,n) For(j,n) if (i!=j) { if ((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<=p[i]*p[i]) { edges[i].pb(j); } } int ans=0; For(i,n) { MEM(b) b[i]=1; int t=0; queue<int> q;q.push(i); while(!q.empty()) { t++; int now=q.front();q.pop(); Rep(j,SI(edges[now])) { if (!b[edges[now][j]]) { q.push(edges[now][j]); b[edges[now][j]]=1; } } } ans=max(ans,t); } printf("%d\n",ans); return 0;}
0 0
- BZOJ 4747-4749题解 Usaco2016 Dec
- bzoj 4749: [Usaco2016 Dec]Moocast dfs
- bzoj 4742 [Usaco2016 Dec]Team Building
- bzoj 4746 [Usaco2016 Dec]Lasers and Mirrors
- BZOJ 4748: [Usaco2016 Dec]Cities and States
- BZOJ 4742 [Usaco2016 Dec]Team Building 动态规划
- BZOJ 4742: [Usaco2016 Dec]Team Building ——DP
- bzoj4742 [Usaco2016 Dec] -- DP
- [bzoj4742][Usaco2016 Dec]Team Building
- 【bzoj4742】[Usaco2016 Dec]Team Building
- bzoj4747 [Usaco2016 Dec]Counting Haybales
- bzoj4742 [Usaco2016 Dec]Team Building
- BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 题解
- [bzoj-1607][Usaco2008 Dec]Patting Heads 轻拍牛头 题解
- 【Usaco2016 FEB】Fenced In 题解
- BZOJ 4580: [Usaco2016 Open]248
- bzoj 4580: [Usaco2016 Open]248
- BZOJ 4412/Usaco2016 Feb Circular Barn(构造)
- 远程Linux服务器下搭建Git远程仓库
- 前端面试题系列(三)
- Activiti工作流教程
- java工程师进阶之路
- maven 笔记---分发第三方jar
- BZOJ 4747-4749题解 Usaco2016 Dec
- LeetCode-83. Remove Duplicates from Sorted List
- chromium中从本地加载gif图片
- AnimationCurve
- 解决UEditor(百度富文本)点击选择图片,打开选择列表慢的问题
- Android 屏幕适配
- Splunk组件和架构详解
- Nginx简介
- JQ 点击隐藏再点击显示