contest 1.13
A.发财兔1A
O(nlogn)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<map> typedef long long ll; using namespace std; ll n,num; ll a[1000005]; ll b[1000005]; ll cnt[1000005]; ll getid(ll x){ return lower_bound(b+1,b+1+num,x)-b; } int main() { scanf("%lld",&n); for(ll i=1;i<=n;i++){ scanf("%lld",&a[i]); b[i]=a[i]; } sort(a+1,a+1+n); sort(b+1,b+1+n); num=unique(b+1,b+1+n)-(b+1); for(ll i=1;i<=n;i++){ ll id=getid(a[i]); cnt[id]++; } ll ans=0; for(ll i=1;i<=n;i++){ ll now=1; while(now<=2*a[n]){ if(now<a[i]||now-a[i]<a[i]) {now*=2;continue;} ll id=getid(now-a[i]); if(b[id]==now-a[i]){ ans+=cnt[id]; if(now-a[i]==a[i]) {ans--;cnt[getid(a[i])]--;} } now*=2; } } printf("%lld\n",ans); return 0; }
C.发财兔1C
树状数组+前缀和差分
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<map> #define lowbit(x) x&(-x) typedef long long ll; using namespace std; int n,m; int a[1000005],A[1000005]; ll c[1000005]; map<int,int> last; struct Query{ int l,r,id; ll ans; }q[1000005]; bool cmp1(Query a,Query b){ return a.r<b.r; } bool cmp2(Query a,Query b){ return a.id<b.id; } void add(int pos,int val){ for(int i=pos;i<=n;i+=lowbit(i)) c[i]^=val; } ll getsum(int pos){ ll ret=0; for(int i=pos;i>0;i-=lowbit(i)) ret^=c[i]; return ret; } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); A[i]=A[i-1]^a[i]; } for(int i=1;i<=m;i++){ scanf("%d%d",&q[i].l,&q[i].r); q[i].id=i; } sort(q+1,q+1+m,cmp1); int now=1; for(int i=1;i<=n;i++){ if(last[a[i]]) add(last[a[i]],a[i]); last[a[i]]=i; add(i,a[i]); while(now<=m&&q[now].r<=i){ int l=q[now].l,r=q[now].r; q[now].ans=(A[r]^A[l-1])^(getsum(r)^getsum(l-1)); now++; } } sort(q+1,q+1+m,cmp2); for(int i=1;i<=m;i++){ printf("%lld\n",q[i].ans); } return 0; }
E.bomb
暴力
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<map> #define inf 0x3f3f3f3f using namespace std; map<double,int> mp; struct Node{ int x,y; }node[1205]; double getk(Node a,Node b){ double x=a.x-b.x; double y=a.y-b.y; if(y==0) return 0; else if(x==0) return inf; else return y*1.0/(x*1.0); } int main() { int n;scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d",&node[i].x,&node[i].y); } int ans=1; for(int i=1;i<=n;i++){ int cnt=1; mp.clear(); for(int j=1;j<=n;j++){ if(j==i) continue; double k=getk(node[i],node[j]); mp[k]++; cnt=max(cnt,mp[k]+1); } ans=max(ans,cnt); } printf("%d\n",ans); return 0; }
F.matrix
预处理+枚举
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include<cstdio> #include<cstring> using namespace std; char Map[5005][5005]; int cnt[5005][5005]; int vis[5005]; int main() { int n,m;scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ scanf("%s",Map[i]+1); } for(int i=1;i<=n;i++){ for(int j=m;j>=1;j--){ if(Map[i][j]=='0') cnt[i][j]=0; else cnt[i][j]=cnt[i][j+1]+1; //printf("%d\n",cnt[i][j]); } } int ans=0; for(int i=1;i<=m;i++){ memset(vis,0,sizeof(vis)); for(int j=1;j<=n;j++){ vis[cnt[j][i]]++; } int all=0; for(int j=n;j>=1;j--){ all+=vis[j]; ans=max(ans,j*all); } } printf("%d\n",ans); return 0; }
转载请注明出处:https://www.cnblogs.com/lllxq/