2- noip模拟赛 DAY2
来源:互联网 发布:淘宝购物的流程 编辑:程序博客网 时间:2024/05/16 09:59
T1 勾股数
因为
分情况考虑:
当输入的a为奇数时,
令
当输入的a为偶数时
令
#include <iostream> #include <cstdio> using namespace std; typedef long long ll; int main(){ ll a; cin >> a; if(a<=2) cout << "-1"; else if(a&1) cout << (a*a-1)/2 << " " << ((a*a-1)/2)+1; else cout << (a*a)/4-1 << " " << ((a*a)/4)+1; return 0; }
T2 区间和
先将原问题转化为
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;ll n, m, val, num;ll a1[100010], sum[100010], summ[100010];void check(ll x){ ll p = 0; for(ll i = 1; i <= n; i ++){ p = max(p, i-1); while(p+1 <= n && sum[p+1] - sum[i-1] <= x) p ++; val += (summ[p] - summ[i-1] - (p-i+1)*sum[i-1]); num += (p-i+1); }}ll solve(ll x){ ll l = 0, r = 1e7, ans = 0, res = 0, cnt = 0; while(l <= r){ ll mid = (l+r) >> 1; val = 0, num = 0, check(mid); if(num >= x) r = mid - 1, ans = mid, res = val, cnt = num; else l = mid + 1; } return res - (cnt-x) * ans;}int main(){ freopen("sum.in", "r", stdin); freopen("sum.out", "w", stdout); scanf("%lld%lld", &n, &m); for(ll i = 1; i <= n; i ++) scanf("%lld", &a1[i]); for(ll i = 1; i <= n; i ++) sum[i] = sum[i-1] + a1[i], summ[i] = summ[i-1] + sum[i]; for(ll i = 1; i <= m; i ++){ ll a, b; scanf("%lld%lld", &a, &b); printf("%lld\n", solve(b) - solve(a-1)); } return 0;}
T3 最长上升子序列
0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的。因此我们可以把0拿出来,对剩下的做
#include <iostream>#include <cstdio>using namespace std;typedef long long ll;const int inf = 1e9;int f[100010], d[100010], a1[100010];int n, cnt, ans;inline int read(){ char c; int ok = 0, num = 0; while(c = getchar()){ if(c <= '9' && c >= '0') ok = 1, num = num*10+c-'0'; else if(ok) return num; }}inline int find(int l, int r, int val){ int ans1 = 0; while(l <= r){ int mid = (l+r)>>1; if(d[mid] >= val) r = mid-1; else ans1 = mid,l = mid+1; } return ans1;}int main(){ scanf("%d", &n); for(int i = 1; i <= n; i ++) d[i] = inf; d[0] = -inf; for(int i = 1; i <= n; i ++) a1[i] = read(); for(int i = 1; i <= n; i ++){ if(a1[i] == 0){ d[ans+1] = d[ans]+1; for(int j = ans; j >= 1; j --) if(d[j] > d[j-1]+1) d[j] = d[j-1]+1; f[i] = ++ ans; continue; } f[i] = find(0,i-1,a1[i])+1; if(a1[i] < d[f[i]]) d[f[i]] = a1[i]; if(f[i] > ans) ans = f[i]; } printf("%d", ans); return 0;}
1 0
- 2- noip模拟赛 DAY2
- contesthunter NOIP模拟赛Day2 8.10
- 洛谷 NOIP 模拟 DAY2
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2)
- CH Round #55 - Streaming #6 (NOIP模拟赛day2)总结
- 计蒜客 2017 NOIP 提高组模拟赛(一)Day2
- 计蒜客 2017 NOIP 提高组模拟赛(二)Day2
- 2017 NOIP 提高组模拟赛(四)Day2(计蒜客)
- 2017.8.19~8.20 noip 模拟 day2
- 4- noip交流赛 DAY2
- 2014.08.10 CH Round#49-Streaming#4(NOIP模拟赛Day2) 总结
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2)(总结)
- CH Round#58 OrzCC杯NOIP模拟赛day2-颜色问题
- CH Round#58 OrzCC杯noip模拟赛day2-树的问题
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2) 解题报告
- noip 模拟赛(by azui大爷) day2 t2(附O(1)求RMQ)
- 【NOIP模拟赛三】并查集+hash day2 third 雪后村庄(好题)
- 计蒜客 2017 NOIP 提高组模拟赛(三)Day2 小区划分
- gridview的Item充满父类
- tar命令中--exclude参数使用详解
- 华为PTN910时钟接口指标
- ThreadLocal学习整理
- jmeter之插件perfmon
- 2- noip模拟赛 DAY2
- java设计模式,部分-整体模式
- 快速排序(随机化版本)
- Python 中类和实例的通俗讲解
- Magical GCD
- 华为6.0的WRITE_SETTING权限问题
- ScrollView嵌套ListView需要使用的View
- mysql unsupported operand type(s) for %: 'tuple' and 'tuple'
- 前端复习--relative盒子的坍塌