• A
  • B
  • C
  • D
  • E

A

打n条龙,龙的攻击力xi,打死每条龙攻击力加yi,你的初始攻击力是s.
如果你的攻击力小于或者等于某条龙的攻击力你就死了.
问你能不能活着回去.

每次贪心打攻击力最小的龙,将龙排序既可.

#include<bits/stdc++.h> //Ithea Myse Valgulious
using namespace std;
const int yuzu=1e5;
struct drn{
int x,y;
bool operator <(const drn &b) const{return x^b.x?x<b.x:y>b.y;}
}d[yuzu|10];
int main(){
int s=read(),n=read(),i;
for (i=1;i<=n;++i) d[i].x=read(),d[i].y=read();
sort(d+1,d+n+1);
for (i=1;i<=n;++i){if (s<=d[i].x) return puts("NO"),0;s+=d[i].y;}puts("YES");
}

B

判断一个数是不是刚好有3个约数.
这个数显然必须是质数的平方.用筛法筛出 106 10 6 10^6以内的质数,然后算出 n−−√ n \sqrt{n}并判断.

#include<bits/stdc++.h> //Ithea Myse Valgulious
using namespace std;
const int yuzu=1e6;
typedef int fuko[yuzu|10];
fuko pr,p;void preprime(){
int i,j;
fill(p+2,p+yuzu+10,1);
for (i=2;i*i<=yuzu;++i){if (p[i]){for (j=i*i;j<=yuzu;j+=i) p[j]=0;}}
}bool judge(ll x){
ll t=sqrt(x);
if (t*t^x) return 0;
return p[t];
}int main(){
preprime();
for (int t=read();t--;){ll x;read(x);puts(judge(x)?"YES":"NO");}
}

C

一个n行m列的01矩阵,每次可以将一行的最后一个数移到最前,或者将一行的最前面一个数移到最后.
求使得某列全为1的最小移动次数,不能输出-1.

每一行用set存储 1 1 1的位置,每一次枚举一列,在行里二分找到离该列最近的两个1" role="presentation" style="position: relative;">111的位置,并求出移动次数相加取最小值.
中间WA了9发,那个suan函数改动得乱七八糟,但是最后终于A掉了.

#include<bits/stdc++.h> //Ithea Myse Valgulious
using namespace std;
const int yuzu=1e4,_=105,inf=yuzu*_;
typedef int fuko[yuzu|10];
char c[yuzu|10];
set<int> s[_];
int n,m;
#define cal(a,b) min(min(abs(a-b),abs(a+m-b)),abs(b+m-a))//把第a行移动到第b行最小的移动次数.
int suan(int r,int c){
int ans;
auto p=s[r].lower_bound(c);
if (p==s[r].end()){ans=min(cal(*s[r].rbegin(),c),cal(*s[r].begin(),c));}else if (p==s[r].begin()){ans=min(cal(*p,c),cal(*s[r].rbegin(),c));}else{ans=min(cal(*p,c),cal(c,*--s[r].lower_bound(c)));}
return ans;
}int main(){
int i,j,ans=inf;
scanf("%d%d",&n,&m);
for (i=1;i<=n;++i){scanf("%s",c+1);for (j=1;j<=m;++j) if (c[j]&1) s[i].insert(j);}
for (j=1;j<=m;++j){int tmp=0;for (i=1;i<=n;++i){if (s[i].empty()) return puts("-1"),0;tmp+=suan(i,j);}ans=min(ans,tmp);}write(ans);
}

D

基本是个裸的最短路.不过当你在第i秒到达某个点的时候这个点有可能被某个tourist占了,
这样你必须要在下一秒才能从这个点出发.

跑个 spfa s p f a spfa即可.(这里 spfa s p f a spfa没死).
在把队首取出来的时候,看看当前点在 dist[i] d i s t [ i ] dist[i]的时间是不是被某个tourist占了,否则将 dist[i]+1 d i s t [ i ] + 1 dist[i]+1,直到没有被占.
这样都是D题我是真的服了.
不过我也有T66个点,那真的是黑历史了,我每次扩展到一个点的时候都把这个点是不是被占判断一遍T飞了.

#pragma GCC optimize("inline",3)
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){int x=0,f=1;char c=gc();for (;!isdigit(c);c=gc()) f^=c=='-';for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');return f?x:-x;}
template <typename mitsuha>
inline bool read(mitsuha &x){x=0;int f=1;char c=gc();for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';if (!~c) return 0;for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');return x=f?x:-x,1;}
template <typename mitsuha>
inline int write(mitsuha x){if (!x) return 0&pc(48);if (x<0) x=-x,pc('-');int bit[20],i,p=0;for (;x;x/=10) bit[++p]=x%10;for (i=p;i;--i) pc(bit[i]+48);return 0;}
inline char fuhao(){char c=gc();for (;isspace(c);c=gc());return c;}
}using namespace chtholly;
using namespace std;
const int yuzu=2e5,inf=0x3f3f3f3f;
typedef int fuko[yuzu|10];
struct edge{int to,w;};
vector<edge> lj[yuzu|10];
set<int> tors[yuzu|10];
fuko vis,dist;
int n,m;
#define key(v) for (;v^n&&tors[v].count(dist[v]);++dist[v])
int spfa(int s){
queue<int> q;
memset(vis,0,sizeof vis);
memset(dist,0x3f,sizeof dist);
q.push(s),vis[s]=1,dist[s]=0;
for (;!q.empty();){int u=q.front();q.pop();vis[u]=0;key(u);for (auto i:lj[u]){int v=i.to,w=i.w;if (dist[v]>dist[u]+w){dist[v]=dist[u]+w;    if (!vis[v]) vis[v]=1,q.push(v);}}}
}int main(){
int i,j;n=read(),m=read();
for (i=1;i<=m;++i){int u=read(),v=read(),w=read();lj[u].push_back(edge{v,w});lj[v].push_back(edge{u,w});}
for (i=1;i<=n;++i){for (j=read();j--;){tors[i].insert(read());}}
spfa(1);
write(dist[n]^inf?dist[n]:-1);
}

E

一张完全图,取m条边出来构造一张图,求这张图和去掉m条边剩下的图的三元环数的总和.
E题有这种题真是扶她服他了.
你只要乱搞一下就可以莫名其妙地A掉了.
令点 i i i的度数是cnt[i]" role="presentation" style="position: relative;">cnt[i]cnt[i]cnt[i],被破坏掉的三元环的数目是 (n−1−cnt[i])×cnt[i] ( n − 1 − c n t [ i ] ) × c n t [ i ] (n-1-cnt[i])\times cnt[i].
由于破坏三元环是双向的,除以二即可.

#pragma GCC optimize("inline",3)
#include<bits/stdc++.h> //Ithea Myse Valgulious
using namespace std;
const int yuzu=1e6;
typedef ll fuko[yuzu|10];
fuko cnt;
int main(){
int n=read(),m=read(),i;
ll ans=0;
for (i=1;i<=m;++i) ++cnt[read()],++cnt[read()];
for (i=1;i<=n;++i) ans+=(n-cnt[i]-1)*cnt[i];
write(1ll*n*(n-1)*(n-2)/6-ans/2);
}

谢谢大家.

Codeforces Round #142 Div.2 题解相关推荐

  1. Codeforces Round #514 (Div. 2)题解

    Codeforces Round #514 (Div. 2)题解 A 喵,直接模拟. B 枚举所有盖章时的,合法的,左上角的位置.能盖的话就盖一下.最后check一下图案是否相等即可 C 一轮一轮的扔 ...

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. 【算法题解】Codeforces Round #817 (Div. 4)题解

    文章目录 Codeforces Round #817 (Div. 4)题解 A. Spell Check B. Colourblindness C. Word Game D. Line E. Coun ...

  4. Codeforces Round #747 (Div. 2)题解

    Codeforces Round #747 (Div. 2)题解 (本博客将持续更新以后每场CF div2的题解,喜欢ACM.OI的小伙伴记得点个关注哟) 昨天夜晚刷网络流刷入迷了,渐渐就忘记了我还要 ...

  5. Codeforces Round #789 (Div. 2)题解

    Codeforces Round #789 (Div. 2)题解 A. Tokitsukaze and All Zero Sequence 原题链接 算法标签 贪心 排序 思路 情况一:数组存在零 → ...

  6. Codeforces Round #748 (Div. 3) 题解 完整A~G

    Codeforces Round #748 (Div. 3) 题解 A. Elections 题意 已知竞选中三个候选人的当前得票数 a , b , c a,b,c a,b,c,现在可以增加任何一个人 ...

  7. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  8. Codeforces Round #734 (Div. 3) 题解

    Hello大家好,今天给大家带来的是 Codeforces Round #734 (Div. 3) 的全题目讲解. 本文链接:https://www.lanqiao.cn/questions/2040 ...

  9. Codeforces Round #462 (Div. 2)题解

    Codeforces Round #462 (Div. 2) B题--我固执的认为1e18是18位数,导致被hack,花了20分钟才检查出这个错误,很僵硬 Codeforces 934C 题意 给定一 ...

最新文章

  1. 认识 Web.config
  2. java异常——捕获异常+再次抛出异常与异常链
  3. Makefile 中:= ?= += =的区别
  4. mysql的几种插入语句_Mysql 几种常见的插入 Insert into,Replace Into,Insert ignore
  5. PyTorch教程(五):Broadcasting
  6. 庖丁解牛看委托和事件(续)
  7. 小程序的 HelloWord 01《 程序员变现指南之 微信QQ 小程序 真的零基础开发宝典》
  8. Vue框架之条件与循环的使用
  9. 【CodeForces - 1084D】The Fair Nut and the Best Path (树形dp)
  10. java中paint方法和paintComponent方法的不同
  11. java 位运算取8位_Java 9 AOT 试用:仅支持 64 位 Linux和java.base 模块编译
  12. 基于java 企业进销存管理系统设计(含源文件)
  13. [LeetCode] Valid Anagram
  14. Week 1 Team Homework #3 from Z.XML-软件工程在北航
  15. python写病毒代码_手把手教你!100行代码,用Python做一个“消灭病毒”的小游戏...
  16. C# OpenCV OpenCVSharp应用实例--LCD屏幕脏污检测
  17. 文本分析苏轼的词以及苏轼的人生轨迹地图
  18. 蒲公英智能云TARA X—永远属于自己的NAS(网络附属存储)
  19. linux分段内存管理中的GDT,LDT,GDTR,LDTR
  20. linux 7.5安装教程,如何在CentOS Linux 7.5上安装 Pip

热门文章

  1. 无领导小组游戏怎样脱颖而出_3种热门游戏在市场上脱颖而出的方式
  2. 【深度学习(deep learning)】花书第12章 应用 读书笔记
  3. caffe 报错 Check failed: error == cudaSuccess (77 vs. 0) an illegal memory access was encountered
  4. banner设圆角_Xbanner圆角展示轮播图
  5. 光晕效果实现和3D流水线的思考
  6. 【Python】 【绘图】绘图的颜色,线型,点型
  7. MQ-135与STM32在TFTLCD上显示数据
  8. 浙江大学 简单计算器
  9. C 语 言 程 序 设 计 --国王的许诺
  10. 《你最美》换发型应用源码