标签:roo 圆心 add div -- cos 交换 iostream include
来源:jisuanke
更新中
A.Tasks
直接贪心
代码:
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> #include<stack> #include<queue> #include<deque> #include<set> #include<vector> #include<map> #include<functional> #define fst first #define sc second #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) #define lson l,mid,root<<1 #define rson mid+1,r,root<<1|1 #define lc root<<1 #define rc root<<1|1 #define lowbit(x) ((x)&(-x)) using namespace std; typedef double db; typedef long double ldb; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> PI; typedef pair<ll,ll> PLL; const db eps = 1e-6; const int mod = 1e9+7; const int maxn = 1e6+100; const int maxm = 6e6+100; //const int inf = 0x3f3f3f3f; const int INF = 0x3f3f3f3f; const int MAXN = maxn; const int MAXM = maxm; const db pi = acos(-1.0); int n, t; int a[maxn]; int main() { scanf("%d %d" ,&n ,&t); for(int i = 0; i < n; i++){ scanf("%d", &a[i]); } sort(a,a+n); int tmp = 0; int ans = 0; for(int i = 0; i < n; i++){ if(tmp+a[i]<=t){ tmp+=a[i];ans++; } }printf("%d", ans); return 0; }
C.Angel‘s Journey
题意:给定一个圆的圆心(rx, ry),半径r,A的坐标(rx, ry-r),B的坐标(x, y),y>ry,只能走圆上以及圆外y>ry的地方,求A到B的最短路
思路:当x<rx-r或x>rx+r的时候直接从半圆的地方走直线,否则在圆弧上走到切点然后走直线
代码:
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> #include<stack> #include<queue> #include<deque> #include<set> #include<vector> #include<map> #include<functional> #define fst first #define sc second #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) #define lson l,mid,root<<1 #define rson mid+1,r,root<<1|1 #define lc root<<1 #define rc root<<1|1 #define lowbit(x) ((x)&(-x)) using namespace std; typedef double db; typedef long double ldb; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> PI; typedef pair<ll,ll> PLL; const db eps = 1e-6; const int mod = 1e9+7; const int maxn = 1e6+100; const int maxm = 6e6+100; //const int inf = 0x3f3f3f3f; const int INF = 0x3f3f3f3f; const int MAXN = maxn; const int MAXM = maxm; const db pi = acos(-1.0); int n, t; int a[maxn]; int main() { double rx,ry,r,x,y; int t; scanf("%d" ,&t); while(t--){ scanf("%lf %lf %lf %lf %lf", &rx,&ry,&r,&x,&y); double ob = sqrt((x-rx)*(x-rx)+(y-ry)*(y-ry)); double ans = sqrt(ob*ob-r*r)+r*(pi/2.0+asin((y-ry)/ob)-acos(r/ob)); if(x<rx-r||x>rx+r){ if(x<rx-r)rx-=r; if(x>rx+r)rx+=r; ans=pi/2+sqrt((x-rx)*(x-rx)+(y-ry)*(y-ry)); } printf("%.4lf\n",ans); } return 0; }
L.Swap
题意:一个排列可以交换前n/2与后n/2,或前n^1个数奇数位置和偶数位置交换,问通过这两个操作最多产生多少个不同的排列
思路:打表发现从第五项开始是2n, n, 12, 4的规律。或者直接交上打表的模拟,由于只有两条链,而且只有一组数据,也能过
代码:
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> #include<stack> #include<queue> #include<deque> #include<set> #include<vector> #include<map> #include<functional> #define fst first #define sc second #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) #define lson l,mid,root<<1 #define rson mid+1,r,root<<1|1 #define lc root<<1 #define rc root<<1|1 #define lowbit(x) ((x)&(-x)) using namespace std; typedef double db; typedef long double ldb; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> PI; typedef pair<ll,ll> PLL; const db eps = 1e-6; const int mod = 1e9+7; const int maxn = 1e6+100; const int maxm = 6e6+100; const int inf = 0x3f3f3f3f; const db pi = acos(-1.0); int n; int a[maxn],b[maxn]; int ans; void gao1(int a[]){ int l = 1; int r = n/2+1; if(n&1)r++; for(int i = 1; i <= n/2; i++){ swap(a[l+i-1],a[r+i-1]); } return; } void gao2(int a[]){ for(int i = 1; i+1 <= n; i+=2){ //printf(" %d %d %d\n",i,a[i],a[i+1]); swap(a[i],a[i+1]); } return; } int sv(int n){ ::n=n; ans=1; int sta=1; for(int i = 1; i <= n; i++)a[i]=b[i]=i; /*if(n==1)return 1; if(n==2)return 2; if(n==3)return 6;*/ gao1(a);gao2(b); //for(int i = 1; i <= n; i++)printf("%d ",a[i]);printf("\n"); //for(int i = 1; i <= n; i++)printf("%d ",b[i]);printf("\n"); while(1){ //for(int i = 1; i <= n; i++)printf("%d ",a[i]);printf("\n"); //for(int i = 1; i <= n; i++)printf("%d ",b[i]);printf("\n"); int ys = 0; sta^=1; for(int i = 1; i <= n; i++){ if(a[i]!=b[i])ys=1; } if(!ys){ ans++;break; } else{ ans+=2; if(sta) {gao1(a);gao2(b);} else {gao1(b);gao2(a);} } } return ans; } int main() { //scanf("%d" ,&n); //sv(3); for(int i = 1; i <= 100; i++){ printf("%d %d\n",i,sv(i)); } scanf("%d", &n); //for(int i = 1; i <= n; i++)scanf("%d", &a[i]); printf("%d",sv(n)); return 0; }
标签:roo 圆心 add div -- cos 交换 iostream include
原文地址:https://www.cnblogs.com/wrjlinkkkkkk/p/10969993.html