A. 直接从状态(0,0)bfs, 这样一定是最小的

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=%P;for (a%=P;n;a=a*a%P,n>>=)if(n&)r=r*a%P;return r;}
ll inv(ll x){return x<=?:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=;char p=getchar();while(p<''||p>'')p=getchar();while(p>=''&&p<='')x=x*+p-'',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+;
#else
const int N = ;
#endif int d, s;
int vis[][];
pii pre[][];
void bfs() {
queue<pii> q;
q.push(pii(,));
vis[][] = ;
while (q.size()) {
int x=q.front().x,y=q.front().y;
q.pop();
REP(i,,) if (y+i<=s) {
int xx=(x*+i)%d,yy=y+i;
if (!vis[xx][yy]) {
vis[xx][yy] = ;
pre[xx][yy]=pii(x,y);
q.push(pii(xx,yy));
}
}
}
}
void dfs2(int x, int y) {
if (x||y) {
dfs2(pre[x][y].x,pre[x][y].y);
printf("%d",y-pre[x][y].y);
}
} int main() {
scanf("%d%d", &d, &s);
bfs();
if (!vis[][s]) return puts("-1"),;
dfs2(,s),hr;
}

B.

C. 事件差分一下, 然后线段树上二分. 刚开始用map维护前k小, 结果TLE on test 77, 感觉复杂度应该对的啊...可能常数太大. 线段树写的时候要注意不仅价格和会爆$int$, 个数和也会爆.... 十分钟打完, WA了一个多小时才发现是少个$long long$

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=%P;for (a%=P;n;a=a*a%P,n>>=)if(n&)r=r*a%P;return r;}
ll inv(ll x){return x<=?:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=;char p=getchar();while(p<''||p>'')p=getchar();while(p>=''&&p<='')x=x*+p-'',p=getchar();return x;}
//head const int N = 1e6+;
int n,k,m,cnt;
ll ans;
vector<pii> s[N];
struct {ll c,s;} tr[N<<];
void update(int o, int l, int r, int p, int c) {
tr[o].c+=c,tr[o].s+=(ll)p*c;
if (l!=r) mid>=p?update(ls,p,c):update(rs,p,c);
}
ll find(int o, int l, int r, int k) {
if (tr[o].c<=k) return tr[o].s;
if (l==r) return min(tr[o].c,(ll)k)*l;
if (tr[lc].c>=k) return find(ls,k);
return tr[lc].s+find(rs,k-tr[lc].c);
}
int main() {
scanf("%d%d%d", &n, &k, &m);
int mx = ;
REP(i,,m) {
int l=rd(),r=rd(),c=rd(),p=rd();
s[l].pb(pii(p,c)), s[r+].pb(pii(p,-c));
mx = max(mx, p);
}
REP(i,,n) {
for (auto &&t:s[i]) update(,,mx,t.x,t.y);
ans += find(,,mx,k);
}
printf("%lld\n", ans);
}

F. 贪心, 11肯定要选, 01和10同时选不会产生负面, 最后从剩余的01或10,和00中选前k大与11匹配.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=%P;for (a%=P;n;a=a*a%P,n>>=)if(n&)r=r*a%P;return r;}
ll inv(ll x){return x<=?:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=;char p=getchar();while(p<''||p>'')p=getchar();while(p>=''&&p<='')x=x*+p-'',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+;
#else
const int N = ;
#endif int n;
priority_queue<int> g[N]; int main() {
scanf("%d", &n);
int tot = , ans = ;
REP(i,,n) {
int x, y;
scanf("%d%d", &x, &y);
g[x].push(y);
if (x==) ++tot,ans+=y;
}
int sz = min(g[].size(),g[].size());
REP(i,,sz-) {
ans+=g[].top()+g[].top();
g[].pop(),g[].pop();
}
int now = g[].size()?:;
REP(i,,tot) g[now].push();
REP(i,,tot) g[].push();
REP(i,,tot) {
if (g[now].top()>g[].top()) {
ans += g[now].top();
g[now].pop();
}
else {
ans += g[].top();
g[].pop();
}
}
printf("%d\n", ans);
}

J. bitset优化

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=%P;for (a%=P;n;a=a*a%P,n>>=)if(n&)r=r*a%P;return r;}
ll inv(ll x){return x<=?:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=;char p=getchar();while(p<''||p>'')p=getchar();while(p>=''&&p<='')x=x*+p-'',p=getchar();return x;}
//head const int N = 2e5+;
int n, m, k, f[N];
char s[N];
const int N1 = , N2 = , N3 = , N4 = ;
const int N5 = , N6 = , N7 = ;
const int N8 = , N9 = , N10 = ;
bitset<N1> b1;
bitset<N2> b2;
bitset<N3> b3;
bitset<N4> b4;
bitset<N5> b5;
bitset<N6> b6;
bitset<N7> b7;
bitset<N8> b8;
bitset<N9> b9;
bitset<N10> b10;
#define solve(b) ({REP(i,1,*f) {\
b.reset();\
b.set();\
REP(j,,*f) if (j!=i) b |= b<<f[j];\
PER(j,,min(n,f[i])) {\
int t = max(,m-k+n+f[i]-j);\
if (b[n-j]) ans = min(ans, j*t);\
}\
}}) void work() {
scanf("%d%d%d%s", &n, &m, &k, s+);
REP(i,'A','Z') f[i]=;
REP(i,,k) ++f[s[i]];
if (n>m) swap(n,m);
*f = ;
REP(i,'A','Z') if (f[i]) f[++*f]=f[i];
int ans = 1e9;
if (n>N9) solve(b10);
else if (n>N8) solve(b9);
else if (n>N7) solve(b8);
else if (n>N6) solve(b7);
else if (n>N5) solve(b6);
else if (n>N4) solve(b5);
else if (n>N3) solve(b4);
else if (n>N2) solve(b3);
else if (n>N1) solve(b2);
else solve(b1);
printf("%d\n", ans);
} int main() {
int t;
scanf("%d", &t);
while (t--) work();
}

2018-2019 ICPC, NEERC, Southern Subregional Contest (codeforces 1070)的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  4. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  5. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  6. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  7. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  8. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  9. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

随机推荐

  1. html密码框value为空,但是总有默认密码(原)

    input输入框加属性:autocomplete="new-password" ,浏览器就不会给他填充默认密码. <input class="form-contro ...

  2. C++入门经典-例3.25-使用循环输出闰年

    1:代码如下: // 3.25.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> usin ...

  3. @RepositoryRestResource注解的使用

    1.Build with Maven <?xml version="1.0" encoding="UTF-8"?> <project xmln ...

  4. 创建新文件(包括上级文件夹),获取外置SD卡的根目录

    public String hebGetExternalRootDir(String externalAndriodSubDirPath){ if ( externalAndriodSubDirPat ...

  5. spark MLlib 概念 1:相关系数( PPMCC or PCC or Pearson's r皮尔森相关系数) and Spearman's correlation(史匹曼等级相关系数)

    皮尔森相关系数定义: 协方差与标准差乘积的商. Pearson's correlation coefficient when applied to a population is commonly r ...

  6. KahnProcessNetwork的Python实现

    用Pytho实现了一个Kahn Process Network: 思路: 用Python的list模拟queue. 每个channel一个queue 用一个list (fgLog)来记录所有push到 ...

  7. python 引流

    Python给抖音自动点赞和评论,实现自动化运营! 都说抖音有毒,一刷就停不下来了.看来抖音这款产品紧紧抓住了人们内心深处的某些需求.当然今天不是来探讨抖音这款产品的啊.今天我们来学习如何用 Pyth ...

  8. beanFactory 设计模式 Bean 生命周期

    写在前面的话 适用读者:有一定经验的,本文不适合初学者,因为可能不能理解我在说什么 文章思路:不会一开始就像别的博客文章那样,Bean 的生命周期,源码解读(给你贴一大堆的源码).个人觉得应该由问题驱 ...

  9. mesh重叠闪烁问题

    我用正交摄像机做了2d游戏,但是导出spine动画文件是个mesh ,在游戏里有时会出现2个Mesh来回切换显示顺序问题,导致闪烁 查了下并没有发现什么解决方案 后面突然发现只要将摄像机的Y轴偏移一点 ...

  10. 24个MySQL面试题

    一.为什么用自增列作为主键? 1.如果我们定义了主键(PRIMARY KEY),那么InnoDB会选择主键作为聚集索引. 如果没有显式定义主键,则InnoDB会选择第一个不包含有NULL值的唯一索引作 ...