codefroces round 320 div2 题解
来源:互联网 发布:php获取ip地理位置 编辑:程序博客网 时间:2024/06/08 10:09
A: 水题
#include <bits/stdc++.h>using namespace std;#define rep(i,a,n) for (int i=a;i<=n;i++)#define per(i,n,a) for (int i=n;i>=a;i--)#define pb push_back#define mp make_pair#define all(x) (x).begin(),(x).end()#define SZ(x) ((int)(x).size())#define fi first#define se secondtypedef vector<int> VI;typedef long long ll;typedef pair<int,int> PII;const ll mod=1000000007;ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}#define Fast_IO ios_base::sync_with_stdio(0);cin.tie(0)int n;int main(){cin>>n;int tmp = 30;int res = 0;while(n){int t = 1<<tmp;if(t > n) tmp--;else n -= t,res++;}cout<<res<<endl;return 0;}
B: 至今也感觉贪心不对。。。
#include <iostream>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cstring>#define N 1000005using namespace std;struct node{int x,y,v;const bool operator < (const node old) const{return v > old.v;}}t[N];bool visit[N];int n,ans[N];int main(){while(scanf("%d",&n) == 1){int i,j,k = 0;for(i = 2;i <= n * 2;i++){for(j = 1;j < i;j++){scanf("%d",&t[k].v);t[k].x = i;t[k].y = j;k++;}}int cont = n;sort(t,t + k);memset(visit,0,sizeof(visit));for(i = 0;i <= n*2*(n*2-1);i++){//cout << t[i].v << endl;if(cont == 0)break;if(visit[t[i].x] == 0 && visit[t[i].y] == 0){visit[t[i].x] = visit[t[i].y] = 1;ans[t[i].x] = t[i].y;ans[t[i].y] = t[i].x;cont--;}}for(i = 1;i <= 2 * n;i++){if(i == 1)cout << ans[i];else cout << " " << ans[i];}putchar('\n');}return 0;}
C:推公式。或者二分
#include <bits/stdc++.h>using namespace std;#define rep(i,a,n) for (int i=a;i<=n;i++)#define per(i,n,a) for (int i=n;i>=a;i--)#define pb push_back#define mp make_pair#define all(x) (x).begin(),(x).end()#define SZ(x) ((int)(x).size())#define fi first#define se secondtypedef vector<int> VI;typedef long long ll;typedef pair<int,int> PII;const ll mod=1000000007;ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}#define Fast_IO ios_base::sync_with_stdio(0);cin.tie(0)int n;int a,b;int main(){cin>>a>>b;if(a < b) {cout<<-1<<endl; return 0;} int t = ((a/b+1)&1)?a/b:a/b+1;double ans = (a+b)*(1.0)/t;printf("%.9f\n", ans);return 0;}
D: 预处理前缀后缀乱搞
#include <bits/stdc++.h>using namespace std;#define rep(i,a,n) for (int i=a;i<=n;i++)#define per(i,n,a) for (int i=n;i>=a;i--)#define pb push_back#define mp make_pair#define all(x) (x).begin(),(x).end()#define SZ(x) ((int)(x).size())#define fi first#define se secondtypedef vector<int> VI;typedef long long ll;typedef pair<int,int> PII;ll powmod(ll a,ll b) {ll res=1;for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}#define Fast_IO ios_base::sync_with_stdio(0);cin.tie(0)#define EPS 1e-8#define LL long long#define MAXN 200010LL l[MAXN] = {0}, r[MAXN] = {0};LL a[MAXN];int main () { int n, k, x; scanf("%d%d%d", &n, &k, &x); for(int i = 1; i <= n; i++) scanf("%I64d", &a[i]); for(int i = 1; i <= n; i++) { l[i] = l[i - 1] | a[i]; } for(int i = n; i >= 1; i--) { r[i] = r[i + 1] | a[i]; } LL maxv = 0; for(int i = 1; i <= n; i++) { LL xx = l[i - 1] | r[i + 1]; LL now = a[i]; for(int j = 0; j < k; j++){ now *= x; } maxv = max(maxv, now | xx); } cout << maxv << endl; return 0;}
E: 三分+最大字段和
#include <bits/stdc++.h>using namespace std;#define rep(i,a,n) for (int i=a;i<=n;i++)#define per(i,n,a) for (int i=n;i>=a;i--)#define pb push_back#define mp make_pair#define all(x) (x).begin(),(x).end()#define SZ(x) ((int)(x).size())#define fi first#define se secondtypedef vector<int> VI;typedef long long ll;typedef pair<int,int> PII;ll powmod(ll a,ll b) {ll res=1;for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}#define Fast_IO ios_base::sync_with_stdio(0);cin.tie(0)int n;double a[200010];#define EPS 1e-8const long long INF = 0x3f3f3f3f;double f[200010];double solve(double x){ double ans1=0; f[1]=a[1]-x; for(int i=2;i<=n;i++) { if(f[i-1]<0) f[i]=a[i]-x; else f[i]=f[i-1]+a[i]-x; ans1=max(ans1,f[i]); } f[1]=(a[1]-x); ans1=max(ans1,-f[1]); for(int i=2;i<=n;i++) { if(f[i-1]>0) f[i]=(a[i]-x); else f[i]=f[i-1]+(a[i]-x); ans1=max(ans1,-f[i]); } return ans1;}int main(){cin>>n;rep(i, 1, n){scanf("%lf", &a[i]);}double l = -10000*(1.0);double r = 10000*1.0;int cnt = 300;double ans;while(cnt--){double mid = (2*l+r)/3;double mmid = (l+2*r)/3;double res1 = solve(mid);double res2 = solve(mmid);if(res1 >= res2){l = mid;ans = mid;}else{ans = mmid;r = mmid;}}double res = 0;double ret = 0;for(int i=1; i<=n; i++){res += a[i] - ans;if(res - EPS < 0)res = 0; ret = max(ret, res);}printf("%.7f\n", ret);return 0;}
0 0
- codefroces round 320 div2 题解
- Codeforces Round #320 div2 题解
- codeforces round 169 div2 题解
- Codeforces Round #214div2题解
- codeforces Round #215 div2 题解
- Codeforces Round #265(div2)题解
- codeforces round 291 div2 题解
- codeforces round 299 div2 题解
- Codeforces Round 313 div2 题解
- codeforces round 315 div2 题解
- codeforces round 319 div2 题解
- codeforces round 321 div2 题解
- Codeforces Round #292 DIV2 题解
- Codeforces Round #409 Div2题解
- codeforces Round 213 div2部分题解
- 【题解】[codeforces round #198 div2]Tourists problem
- Codeforces round 440 div2 总结&&题解
- codeforces Codeforces Round #407 Div2题解
- 标准模板库STL学习总结
- Hello JSP!——内置对象基础练习题
- 解决td.innerHTML赋值出现发生未知错误
- Android Asynctask
- WXHL 学习文章连载 (十)
- codefroces round 320 div2 题解
- Android studio改变字体大小
- Eclipse常用快捷键
- *HDU 4427 - Math Magic(dp)
- ReactiveCocoa与Functional Reactive Programming
- js之location对象
- 二叉树的遍历-递归与非递归 - 海子
- 使用oracle遇到的相关函数
- Spark学习笔记之-Spark-Standalone下driver和executor分配