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. Aragorn's Story

    A - Aragorn's Story 直接套 线段树+树剖 板子 代码: // Created by CAD on 2019/8/12. #include <bits/stdc++.h> ...

  2. Unity3D_(游戏)卡牌01_启动屏界面

      卡牌2D游戏展示 (游戏代码放到  卡牌04_游戏界面  文章最后面~) 游戏项目已托管到github上(里面有个32bit可执行文件) 传送门 规则 开始游戏每张卡牌初始翻开展示 展示几秒后卡牌 ...

  3. 大哥带的XSS练习

    0x01反射型 <script>alert("zhong")</script> 可以看见什么都没有过滤 0x02存储型XSS http://www.xss_ ...

  4. 两种建立堆的方法HeapInsert & Heapify

    参考 堆排序中两种建堆方法的比较 第一种方法HeapInsert 它可以假定我们事先不知道有多少个元素,通过不断往堆里面插入元素进行调整来构建堆. 它的大致步骤如下: 首先增加堆的长度,在最末尾的地方 ...

  5. Javascript事件:this.value()和this.select()

    1.JavaScript的this.value() <asp:TextBox ID="txtComment" runat="server" Text=&q ...

  6. shiro的web.xml的配置

    <servlet> <servlet-name>springDispatcherServlet</servlet-name> <servlet-class&g ...

  7. 剑指offer31----栈的压入、弹出序列

    题目:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对 ...

  8. 黑马lavarel教程---3、数据库和视图注意点

    黑马lavarel教程---3.数据库和视图注意点 一.总结 一句话总结: 使用其实都很简单,MVC的框架都很像,用的时候直接可以去看手册,这样才能记得住 1.数据库删除操作注意? 删非删:很多网站的 ...

  9. Ubuntu系统下各种报错杂烩(持续更新)

    在Github时报Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hos ...

  10. 锋利的jQuery(第二版) 初读笔记

    window.onload(): 必须等待网页中所有的内容加载完毕后(包括图片)才能执行. $(document).ready(): 网页中所有DOM结构绘制完毕后就执行,可能DOM元素关联的东西并没 ...