标签:os io for ar 问题 div amp size
A 先判断邻边长度是否相等,不是就无法构成正方形,否则的话位置坐标搞一下
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <algorithm> #include <bitset> #include <vector> #include <set> #include <queue> #include <stack> #include <list> #include <utility> #include <deque> #include <map> #define Inf 0x3f3f3f3f #define Maxn 1000005 #define LL long long #define lowbit(x) x&(-x) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define re freopen("in.txt","r",stdin) #define wr freopen("out.txt","w",stdout) using namespace std; int main() { int x1,y1,x2,y2; //re; //wr; while(cin>>x1>>y1>>x2>>y2) { if(x1==x2) { cout<<x1+abs(y1-y2)<<" "<<y1<<" "<<x2+abs(y1-y2)<<" "<<y2<<endl; } else if(y1==y2) { cout<<x1<<" "<<y1+abs(x1-x2)<<" "<<x2<<" "<<y2+abs(x1-x2)<<endl; } else if(abs(x2-x1)==abs(y2-y1)) { cout<<x1<<" "<<y2<<" "<<x2<<" "<<y1<<endl; } else puts("-1"); } return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <algorithm> #include <bitset> #include <vector> #include <set> #include <queue> #include <stack> #include <list> #include <utility> #include <deque> #include <map> #define Inf 0x3f3f3f3f #define Maxn 1000005 #define LL long long #define lowbit(x) x&(-x) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define re freopen("in.txt","r",stdin) #define wr freopen("out.txt","w",stdout) using namespace std; int main() { int a[Maxn],i,Max,Min; LL p,q,n; //re; //wr; while(cin>>n) { p=0;q=0; Max=-1;Min=Inf; for(i=0;i<n;i++) { cin>>a[i]; Max=max(Max,a[i]); Min=min(Min,a[i]); } for(i=0;i<n;i++) { if(a[i]==Max) p++; if(a[i]==Min) q++; } if(Max!=Min) cout<<Max-Min<<" "<<p*q<<endl; else cout<<0<<" "<<n*(n-1)/2<<endl; } return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <algorithm> #include <bitset> #include <vector> #include <set> #include <queue> #include <stack> #include <list> #include <utility> #include <deque> #include <map> #define Inf 0x3f3f3f3f #define Maxn 1000005 #define LL long long #define lowbit(x) x&(-x) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define re freopen("in.txt","r",stdin) #define wr freopen("out.txt","w",stdout) using namespace std; int ans[1005][1005],s; bool check(int n,int k,int d) { int tmp=1; while(d--) { tmp*=k; if(tmp>=n) return true; } return false; } void T(int n,int d,int k) { int p=0; vector<int> t; while(n) { t.push_back(n%k); n/=k; } if(t.size()<d) { int tmp=d-t.size(); while(tmp--) ans[s][p++]=1; } for(int i=t.size()-1;i>=0;i--) ans[s][p++]=t[i]+1; s++; } int main() { int n,k,d; //re; //wr; while(~scanf("%d%d%d",&n,&k,&d)) { s=0; memset(ans,0,sizeof(ans)); if(!check(n,k,d)) { puts("-1"); continue; } else { for(int i=0;i<n;i++) T(i,d,k); } for(int j=0;j<d;j++) for(int i=0;i<n;i++) printf("%d%c",ans[i][j],i==n-1?'\n':' '); } return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <algorithm> #include <bitset> #include <vector> #include <set> #include <queue> #include <stack> #include <list> #include <utility> #include <deque> #include <map> #define Inf 0x3f3f3f3f #define Maxn 1000005 #define LL long long #define lowbit(x) x&(-x) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define re freopen("in.txt","r",stdin) #define wr freopen("out.txt","w",stdout) using namespace std; LL tree[Maxn]; void add(int pos,int n,int x) { for(int i=pos;i<=n;i+=lowbit(i)) tree[i]+=x; } LL sum(int pos) { LL ans=0; for(int i=pos;i>0;i-=lowbit(i)) ans+=tree[i]; return ans; } int main() { map<int,int> mp; int i,n,a[Maxn],f1[Maxn],f2[Maxn]; LL ans; //re; //wr; while(~scanf("%d",&n)) { ans=0; memset(f1,0,sizeof(f1)); memset(f2,0,sizeof(f2)); for(i=1;i<=n;i++) scanf("%d",&a[i]); mp.clear(); for(i=1;i<=n;i++) mp[a[i]]++,f1[i]=mp[a[i]]; mp.clear(); for(i=n;i>=1;i--) mp[a[i]]++,f2[i]=mp[a[i]],add(f2[i],n,1); for(i=1;i<n;i++) { add(f2[i],n,-1); ans+=sum(f1[i]-1); } printf("%I64d\n",ans); } return 0; }
CF #261 DIV2 A,B,C,D,布布扣,bubuko.com
标签:os io for ar 问题 div amp size
原文地址:http://blog.csdn.net/hqu_fritz/article/details/38613679