Semana i 2018
思路: dp水题
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int MOD = 1e9 + , N = 1e6 + ;
LL dp[N];
int main() {
int T, n;
dp[] = ;
for (int i = ; i < N; i++) {
for (int j = max(, i-); j < i; j++) dp[i] = (dp[i] + dp[j]) % MOD;
}
scanf("%d", &T);
for (int i = ; i <= T; i++) {
scanf("%d", &n);
printf("%lld\n", dp[n/]);
}
return ;
}
思路:用set
n^2logn暴力枚举
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 2e3 + ;
pair<int, pii> a[N];
multiset<pii> s1;
multiset<int> s2;
int main() {
int n, k;
scanf("%d %d", &n, &k);
for (int i = ; i <= n; i++) scanf("%d %d %d", &a[i].fi, &a[i].se.fi, &a[i].se.se);
sort(a+, a++n);
LL ans = 1e16;
for (int i = ; i <= n; i++) {
s1.insert(a[i].se);
if(i >= k) {
s2.clear();
for (auto it : s1) {
s2.insert(it.se);
if(s2.size() > k) s2.erase(--s2.end());
if(s2.size() == k) {
ans = min(ans, 1LL*a[i].fi + 1LL*it.fi + 1LL*(*--s2.end()));
}
}
}
}
printf("%lld\n", ans);
return ;
}
思路:水题, 减S取模
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 1e3 + ;
char s[N];
bool isAlphaBete(char c){
return c>='A'&&c<='Z'||c>='a'&&c<='z';
}
int main() {
int n, S;
scanf("%d %d", &n, &S);
S %= ;
char c;
c = getchar();
while((c = getchar())!=EOF){
if(isupper(c)) {
int t = c - 'A';
t = (t + - S) % ;
c = 'A' + t;
}
else if(islower(c)) {
int t = c - 'a';
t = (t + - S) % ;
c = 'a' + t;
}
putchar(c);
}
return ;
}
思路:贪心
假设相邻两个元素a, b, 在此之前的大象的体重为w
那么按a前b后的顺序的花费是 w*a.c + w*a.r*b.c
按b前a后的顺序的花费是 w*b.c + w*b.r*a.c
无论什么顺序,经过这两个元素后大象的体重都是w*a.r*b.r
那么a在b前的条件是w*a.c + w*a.r*b.c < w*b.c + w*b.r*a.c
即 a.c + a.r*b.c < b.c + b.r*a.c
按这个条件写个cmp函数排个序即可
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 1e5 + ;
const LL INF = (1ll<<);
struct node {
int c;
double r;
}a[N];
int n, w;
bool cmp(node a, node b) {
return a.c + b.c*a.r < b.c + a.c*b.r;
} void solve() {
double ans = INF;
sort(a+, a++n, cmp);
double tw = w, tans = ;
for (int i = ; i <= n; i++) {
tans += tw * a[i].c;
tw *= a[i].r;
}
ans = min(ans, tans);
printf("%.10f\n", ans);
}
int main() {
scanf("%d %d", &n, &w);
for (int i = ; i <= n; i++) scanf("%d %lf", &a[i].c, &a[i].r);
solve();
return ;
}
思路:一个向量旋转乘以下面的旋转矩阵即可(Θ > 0 表示逆时针)
然后多边形旋转的话就一个点不动,其他点绕改点旋转
旋转好后将多边形左下角移动到与x轴正半轴和y正半轴相切,然后按w*h等比例缩放
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 1e5 + ;
const int INF = 0x7f7f7f7f;
const double eps = 1e-;
//考虑误差的加法
double add(double a, double b) {
if(fabs(a + b) < eps * (fabs(a) + fabs(b))) return ;
return a + b;
}
//考虑误差的与0比较
int dcmp(double x) {
if(fabs(x) < eps) return ;
else return x<?-:;
}
struct P {
double x, y;
P(){}
P(double x, double y) :x(x), y(y){}
bool operator == (P p) {
return dcmp(x - p.x) == && dcmp(y - p.y) == ;
}
P operator + (P p) {
return P(add(x, p.x), add(y, p.y));
}
P operator - (P p) {
return P(add(x, -p.x), add(y, -p.y));
}
P operator * (double p) {
return P(x * p, y * p);
}
P operator / (double p) {
return P(x / p, y / p);
}
//点积
double dot(P p) {
return add(x * p.x, y * p.y);
}
//叉积
double cross(P p) {
return add(x * p.y, -y * p.x);
}
}p[N];
typedef P Vector;
//向量逆时针旋转
Vector Rotate(Vector a,double rad) {
return Vector(a.x * cos(rad) - a.y * sin(rad), a.x * sin(rad) + a.y * cos(rad));
} int main() {
int a, w, h, n;
scanf("%d %d %d %d", &a, &w, &h, &n);
double A = a*pi/;
for (int i = ; i <= n; i++) scanf("%lf %lf", &p[i].x, &p[i].y);
for (int i = ; i <= n; i++) p[i] = p[] + Rotate(p[i] - p[], A);
double mnx = INF, mny = INF;
for (int i = ; i <= n; i++) mnx = min(mnx, p[i].x), mny = min(mny, p[i].y);
for (int i = ; i <= n; i++) p[i].x -= mnx, p[i].y -= mny;
double mxx = , mxy = ;
for (int i = ; i <= n; i++) mxx = max(mxx, p[i].x), mxy = max(mxy, p[i].y);
for (int i = ; i <= n; i++) p[i].x = p[i].x*w/mxx, p[i].y = p[i].y*h/mxy;
for (int i = ; i <= n; i++) printf("%.10f %.10f\n", p[i].x, p[i].y);
return ;
}
思路:首先将给的小数乘以10000得到式子 d / 100000 中的 d, 然后10000/gcd(10000, d) 就是答案
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head char s[];
int main() {
int T;
scanf("%d", &T);
for (int i = ; i <= T; i++) {
scanf("%s", s);
int n = strlen(s);
int t = ;
for (int i = ; i < n; i++) {
t = t* + s[i] - '';
}
for (int i = n; i < ; i++) {
t = t*;
}
int d = __gcd(t, );
printf("%d\n", /d);
}
return ;
}
G A+B+C
思路:水题, (a*d*f + c*b*f + e*b*d) / (b*d*f) 约分后即是答案
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head int main() {
int T;
LL a, b, c, d, e, f;
scanf("%d", &T);
for (int i = ; i <= T; i++) {
scanf("%lld/%lld %lld/%lld %lld/%lld", &a, &b, &c, &d, &e, &f);
LL up = a*d*f + c*b*f + e*b*d;
LL down = b*d*f;
LL d = __gcd(up, down);
up /= d;
down /= d;
printf("%lld/%lld\n", up, down);
}
return ;
}
思路:水题, 题意难懂, 把a drink理解为一瓶酒
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int MOD = 1e9 + , N = 1e6 + ;
LL dp[N];
int main() {
int T, n, k;
scanf("%d", &T);
for (int i = ; i <= T; i++) {
scanf("%d %d", &n, &k);
int b = n*(n+)/;
if(k < b) puts("Too drunk to count");
else if((k-b) % n == ) printf("%d\n", n++(k-b)/n);
else puts("Too drunk to count");
}
return ;
}
思路: 最大流, 要拆点
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 2e3 + , M = 6e3 + ;
const int INF = 0x3f3f3f3f;
pii a[N];
piii b[N];
struct edge {
int to, cap, rev;
};
vector<edge> g[M];
int level[M], iter[M], mxv = ;
void add_edge(int from, int to, int cap) {
g[from].pb({to, cap, g[to].size()});
g[to].pb({from, , g[from].size()-});
}
void bfs(int s) {
for (int i = ; i <= mxv; i++) level[i] = -;
queue<int> q;
level[s] = ;
q.push(s);
while(!q.empty()) {
int v = q.front();
q.pop();
for (edge &e : g[v]) {
if(e.cap > && level[e.to] < ) {
level[e.to] = level[v] + ;
q.push(e.to);
}
}
}
} int dfs(int v, int t, int f) {
if (v == t) return f;
for (int &i = iter[v]; i < g[v].size(); i++) {
edge &e = g[v][i];
if(e.cap > && level[v] < level[e.to]) {
int d = dfs(e.to, t, min(f, e.cap));
if(d > ) {
e.cap -= d;
g[e.to][e.rev].cap += d;
return d;
}
}
}
return ;
} int max_flow(int s, int t) {
int flow = ;
for(;;) {
bfs(s);
if(level[t] < ) return flow;
for (int i = ; i <= mxv; i++) iter[i] = ;
int f;
while((f = dfs(s, t, INF)) > ) {
flow += f;
}
}
}
int main() {
int n, m;
LL s;
scanf("%d %d %lld", &n, &m, &s);
if(s < ) return *puts("NO");
s -= ;
for (int i = ; i <= n; i++) scanf("%d %d", &a[i].fi, &a[i].se);
for (int i = ; i <= m; i++) scanf("%d %d %d", &b[i].fi.fi, &b[i].fi.se, &b[i].se);
int st = ;
for (int i = ; i <= n; i++) add_edge(st, i, );
for (int i = ; i <= n; i++) {
for (int j = ; j <= m; j++) {
int dx = abs(b[j].fi.fi - a[i].fi), dy = abs(b[j].fi.se - a[i].se);
if(1ULL*dx*dx + 1ULL*dy*dy <= 1ULL*s*s) {
add_edge(i, n+j, );
}
}
}
for (int i = ; i <= m; i++) {
add_edge(i+n, i+n+m, b[i].se);
}
mxv = m+n+m+;
for (int i = ; i <= m; i++) {
add_edge(i+n+m, mxv, INF);
}
if(max_flow(st, mxv) == n) puts("YES");
else puts("NO");
return ;
}
思路:线段树, 用long double
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 1e5 + ;
const long double up = pow((long double)2.0, );
long double tree[N<<];
void push_up(int rt) {
tree[rt] = tree[rt<<] * tree[rt<<|];
}
void build(int rt, int l, int r) {
if(l == r) {
cin >> tree[rt];
return ;
}
int m = l+r >> ;
build(ls);
build(rs);
push_up(rt);
}
void update(int p, double x, int rt, int l, int r) {
if(l == r) {
tree[rt] = (long double)x;
return ;
}
int m = l+r >> ;
if(p <= m) update(p, x, ls);
else update(p, x, rs);
push_up(rt);
}
long double query(int L, int R, int rt, int l, int r) {
if(L <= l && r <= R) return tree[rt];
int m = l+r >> ;
long double ans = ;
if(L <= m) ans *= query(L, R, ls);
if(R > m) ans *= query(L, R, rs);
return ans;
}
int main() {
int n;
scanf("%d", &n);
build(, , n);
int q, ty, l, r, x;
double p;
scanf("%d", &q);
for (int i = ; i <= q; i++) {
scanf("%d", &ty);
if(ty == ) {
scanf("%d %lf", &x, &p);
update(x, p, , , n);
}
else {
scanf("%d %d", &l, &r);
long double t = query(l, r, , , n);
if(t >= up) printf("INFINITE!\n");
else cout << fixed << setprecision() << t << '\n';
}
}
return ;
}
Semana i 2018的更多相关文章
- 2018. The Debut Album
http://acm.timus.ru/problem.aspx?space=1&num=2018 真心爱过,怎么能彻底忘掉 题目大意: 长度为n的串,由1和2组成,连续的1不能超过a个,连续 ...
- Math.abs(~2018),掌握规律即可!
Math.abs(~2018) 某前端群的入门问题长姿势了,一个简单的入门问题却引发了我的思考,深深的体会到自己在学习前端技术的同时忽略遗忘了一些计算机的基础知识. 对于 JS Math对象没什么可说 ...
- 肖秀荣8套卷2018pdf下载|2018肖秀荣冲刺8套卷pdf下载电子版
肖秀荣8套卷2018pdf下载|2018肖秀荣冲刺8套卷pdf下载电子版 下载链接: https://u253469.ctfile.com/fs/253469-229815828
- 2018年的UX设计师薪酬预测,你能拿多少?
以下内容由Mockplus团队翻译整理,仅供学习交流,Mockplus是更快更简单的原型设计工具. 一个经验丰富的设计师完全可以根据地区和专业来可以预期薪酬之间的差距,其中悬殊最高可达80K. 本 ...
- Hello 2018, Bye 2017
2017年过去了,过去一年经历了太多,改变了好多好多,可以说人生进入了另一个阶段,有可能是成熟吧. 回顾2017 去年换了新工作,离开了将近工作了8年的公司,不带走一丝云彩,为其任劳任怨,最后没有任何 ...
- New Life With 2018
2017年转眼过去了.对自己来说.这一大年是迷茫和认知的一年.我的第一篇博客就这样记录下自己的历程吧 一:选择 从进入这一行到现在已经一年多了,2016年11月份就像所有的应届毕业生一样,都贼反感毕业 ...
- 2017 年终总结 & 2018 年度计划
不立几个 Flag,都不知道怎么作死 2017 年度计划完成情况: 1.健身时间不少于350天: 未完成 中断了22天,实际运动 343天 2.至少每个月看一本书: 及格 <切尔诺贝利的 ...
- [总结]-2018 w1
不想总结 2017,过去的就过去吧,不过自己在 2017 年还是收获了很多,最重要的就是赚钱.赚钱还是需要两把刷子,所以,2018 的小目标就是学习数据分析和机器学习.希望自己在这两个领域能搞点事情. ...
- 2018年手机应用UI设计趋势预测
用户需求瞬息万变,而手机软件UI设计为适应变化的用户需求,也相应的发生着变化.但是,这并不意味着用户需求和UI设计趋势就是无迹可寻的.事实上,根据前几年的手机app界面设计变化的特点,尤其是2017年 ...
随机推荐
- 设置PhoenixOS进入图形界面
phoenix操作系统很淡疼的一点就是每次启动都进入命令行界面,而且要想进入图形界面,每次都得配置. 开启虚拟机后,会出现引导界面,在虚拟机中连按2次“E”键进行编辑 输入参数“空格nomodeset ...
- oracle exadata一体机虚拟机
14年参加partner培训的时候,拿了份oracle exadata一体机虚拟机,有兴趣的可以试试,不过比较大,压缩后10GB,解压后50GB,启动后直接可用,2RAC节点+1存储节点,环境最好内存 ...
- 针对数据泵导出 (expdp) 和导入 (impdp)工具性能降低问题的检查表 (文档 ID 1549185.1)
针对数据泵导出 (expdp) 和导入 (impdp)工具性能降低问题的检查表 (文档 ID 1549185.1) 文档内容 适用于: Oracle Database – Enterprise Edi ...
- oracle已知会导致错误结果的bug列表(Bug Issues Known to cause Wrong Results)
LAST UPDATE: 1 Dec 15, 2016 APPLIES TO: 1 2 3 4 Oracle Database - Enterprise Edition - Versi ...
- 我是这样做APP的:击中用户的痛点(转)
击中用户的痛点 点评,感觉取名叫做“用户痛点的取舍”更加合适.很多公司.项目的失败完全取决于决策人取舍的失败,一味地追求大而全.迎合上级领导,专断而没有和团队做客观的分析.本文虽然以一个应该来说并不复 ...
- linux 实时显示网速bash
执行方法先授权再运行 chmod +x shi.sh脚本+网卡名称 ./shi.sh ens33 #!/bin/bash while [ "1" ] do eth=$1 RXpre ...
- 零基础Python爬虫实现(百度贴吧)
提示:本学习来自Ehco前辈的文章, 经过实现得出的笔记. 目标 http://tieba.baidu.com/f?kw=linux&ie=utf-8 网站结构 学习目标 由于是第一个实验性质 ...
- tf.nn.relu
tf.nn.relu(features, name = None) 这个函数的作用是计算激活函数 relu,即 max(features, 0).即将矩阵中每行的非最大值置0. import tens ...
- 為什麼gnome-terminal中不能使用ctrl_shift_f來進行查找? 是因為 跟输入法的全局设置衝突了!
但是,也要注意, 为什么ctrl+shift_f有时候可以使用, 有时候又不可以使用? 是因为, 这个跟输入法的状态有关, 如果输入法是英文, 那么中文的 "简体/繁体切换快捷键ctrl+s ...
- 三星固态硬盘ssd产品线收集
目录 三星ssd按时间展示: 三星ssd后缀带a与不带a的区别,举其中一例: 下面是从三星中国的官网截图的产品线: 产品线列表: 总结: 参考: 最近在淘宝看到了很多拆机ssd,三星作为世界上唯一一家 ...