https://codeforces.com/contest/1228/problem/A

A. Distinct Digits

超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每一位的数字不相同,找出满足要求的最小的那个数输出,没有找到就输出-1;

 #include<bits/stdc++.h>
using namespace std;
bool check(int n){
int vis[]={};
while(n){
if(!vis[n%]) vis[n%]=;
else return false;
n/=;
}
return true;
}
int main()
{
int l,r;
cin>>l>>r;
for(int i = l;i <=r;++i){
if(check(i)){
cout<<i<<endl;return ;
}
}
cout<<"-1"<<endl;
return ;
}

AC代码

https://codeforces.com/contest/1228/problem/B

B. Filling the Grid

也很简单,,自己读题没读清导致前面白wa了好几发。给一个n*m的grid,然后告诉你每一行每一列从边界处开始连续的黑块个数,然后求满足这个条件的有多少种情况,输出结果mod1e9+7。

然后要注意,如果没有方案数是输出0的。

因为h,w<=1e3,所以构建个二维数组就好了,在连续黑色块的位置标记1,后一位还有空位的话标-1,-1表示这个地方不能变黑,如果标1和-1重复了,那么方案数就是0,如果可以把这个基础的图构造出来的话,统计一下0的个数ans,输出2的ans次方就好了(因为0可填黑可填白)

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+;
int mp[][];
long long power(long long a,long long b)///a是底数,b是次幂
{
long long ans=;
for(;b!=;b>>=)
{
if(b&) ans=(long long)ans*a%mod;
a=(long long)a*a%mod;
}
return ans;
} int main()
{
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++)
{
int a;cin>>a;
for(int j=;j<=a;j++)
{
mp[i][j]=;
}
mp[i][a+]=-;
}
int f=;
for(int i=;i<=m;i++)
{
int a;cin>>a;
for(int j=;j<=a;j++)
{
if(mp[j][i]==-) f=;
mp[j][i]=;
}
if(mp[a+][i]==) f=;
mp[a+][i]=-;
}
if(f==)
cout<<<<endl;
else
{
int ans=;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(mp[i][j]==)
ans++;
cout<<power(,ans)<<endl;
}
}

AC代码

https://codeforces.com/contest/1230/problem/C

C. Primes and Multiplication

写这道题的时候疯狂挨骂emmm,lj好好反思。

根据题目定义把要求的东西展开,然后要用到的一个结论就是求1-n中质因子x的个数是求Σ(n/x^k)(k=1,2,3...)

还学到了个求质因子的方法? 害...不会的东西太多了

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+;
ll sq(ll a,ll b){
ll cnt=;
while(b){
if(b&)cnt=cnt%mod*a%mod;
a=a*a%mod;
b>>=;
}
return cnt%mod;
}
vector<ll>s;
int main(){
ll ans= ,x,n;
cin>>x>>n;
for(ll i = ;i *i<= x;++i){
if(x%i==)s.push_back(i);
while(x%i==)x/=i;
}
s.push_back(x);
for(int i = ;i< s.size();++i){
if(s[i]==) continue;
ll sum=,temp=s[i],a=s[i];
while(temp<=n){
sum+=n/temp;
if(temp>n/a)break;
temp*=a;
} ans=ans*sq(a,sum)%mod;ans%=mod;
}
cout<<ans<<endl;
return ;
}

AC代码

https://codeforces.com/contest/1228/problem/D

D. Complete Tripartite

给n个点m条边,然后构造三个顶点集,其中任一顶点集内的顶点两两之间没有边,然后该顶点集的任一顶点都和不属于这个顶点集的所有点有边。

如果可以就输出每个顶点所属的集合,不可以就输出-1;

emmmmmm,然后按照题意写就好了,先全部放在集合1,然后和集合1有边的就去集合2,然后集合2内部有边的就放到集合3去,再检查集合内部有没有连接的边。

如果都没问题了之后再检查每个点是否和其他不属于它集合的点有边,那么就想办法检查一遍和她连接的点在另外两个集合的个数是不是 等于另外两个集合的顶点数

 #include<bits/stdc++.h>
using namespace std;
const int N = 1e5+;
vector<int>s[N];
int pre[N],cnt1=,cnt2=,cnt3=,temp1,temp2,temp3;
struct ac{
int x,y;
}a[];
int main()
{
int n,m;
cin>>n>>m;
for(int i = ;i <=n;++i)pre[i]=;cnt1=n;
for(int i = ;i <m;++i){
cin>>a[i].x>>a[i].y;
s[a[i].x].push_back(a[i].y);s[a[i].y].push_back(a[i].x);
} for(int i = ;i <= n; ++i){
if(s[i].size()<){cout<<"-1"<<endl;return ;}
for(int j = ;j < s[i].size();++j){
if(pre[i]==)
if(pre[s[i][j]]==)pre[s[i][j]]=,cnt1--,cnt2++;
}
}
for(int i = ;i <= n;++i){
for(int j = ;j <s[i].size();++j){
if(pre[i]==)
if(pre[s[i][j]]==)pre[s[i][j]]=,cnt2--,cnt3++;
}
}
if(cnt1==||cnt2==||cnt3==){
cout<<"-1"<<endl;return ;
} for(int i = ;i <=n;++i){
temp1=temp2=temp3=;
for(int j = ;j < s[i].size();++j){
if(pre[i]==pre[s[i][j]]){
cout<<"-1"<<endl;return ;
}
if(pre[i]==){
if(pre[s[i][j]]==)temp2++;
else if(pre[s[i][j]]==)temp3++;
}
else if(pre[i]==){
if(pre[s[i][j]]==)temp1++;
else if(pre[s[i][j]]==)temp3++;
}
else if(pre[i]==){
if(pre[s[i][j]]==)temp2++;
else if(pre[s[i][j]]==)temp1++;
}
}
if(pre[i]==){
if(temp2<cnt2||temp3<cnt3){
cout<<"-1"<<endl;return ;
}
}
else if(pre[i]==){
if(temp1<cnt1||temp3<cnt3){
cout<<"-1"<<endl;return ;
}
}
else if(pre[i]==){
if(temp2<cnt2||temp1<cnt1){
cout<<"-1"<<endl;return ;
}
}
}
for(int i = ;i <=n;++i)cout<<pre[i]<<" ";cout<<endl;
}

AC代码

emmmm我也不清楚为啥这个题这么暴力的写都能过。。可能这就是div3吧(真实(然而我写了很久

Codeforces Round #589 (Div. 2) (e、f没写)的更多相关文章

  1. Codeforces Round 212 Div 2 报告(以前没写完,现在也没心情补了,先就这样吧)

    A. Two Semiknights Meet 题目大意:有一个8x8的棋盘,上面放有两个骑士,骑士以“田字”的方式走.每个方格都被定义为good或者bad,问骑士能否在good的格子中相遇? 由于骑 ...

  2. Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理

    Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\) ...

  3. Codeforces Round #573 (Div. 1) 差F

    Codeforces Round #573 (Div. 1) E 题意:二维平面上有 n 个点,你可以放至多 m 条直线使得 (0,0) 与每个点的连线至少与一条直线相交.求原点与所有直线的距离最小值 ...

  4. Codeforces Round #541 (Div. 2) (A~F)

    目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...

  5. Codeforces Round 589 (Div. 2) 题解

    Is that a kind of fetishism? No, he is objectively a god. 见识了一把 Mcdic 究竟出题有多神. (虽然感觉还是吹过头了) 开了场 Virt ...

  6. Codeforces Round #589 (Div. 2)

    目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Com ...

  7. Codeforces Round #346 (Div. 2) E F

    因为很久没有个人认真做题了 昨天晚上开了场虚拟cf来锻炼个人手速 选的是第一次做cf的场 那时候7出3还被hack...之后也没补题 这次做的时候顺便回忆了一下以前比赛的时候是怎么想的 发现经验还是很 ...

  8. Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)

    F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...

  9. Codeforces Round #589 (Div. 2) D. Complete Tripartite(染色)

    链接: https://codeforces.com/contest/1228/problem/D 题意: You have a simple undirected graph consisting ...

随机推荐

  1. 运行时错误:“stack around the variable…was corrupted”

    造冰箱的大熊猫@cnblogs 2018/11/1 引发问题的代码片段如下 WORD var; scanf ( "%d", &var ); 包含上述代码的程序,编译正常,运 ...

  2. hdu 2553 八皇后问题 基础

    题意:给你一个n*n的棋盘,要求放n个皇后: <span style="font-size:18px;">#include <iostream> #incl ...

  3. 我不熟悉的vector

    构造函数 使用迭代器构造vector的一种方式: //将v[begin(), end())区间中的元素拷贝给本身 vector(v.begin(),v.end()); 在这个构造函数中,传入普通数组也 ...

  4. tomcat 散点杂记

    tomcat有很多细碎的知识点和一些坑点,我将再次记录 域名直指项目 我们经常访问项目都要带上项目目录 eg: http://xwiki.test.com/xwiki or http://jenkin ...

  5. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2) G1. Into Blocks (easy version)

    题目:https://codeforc.es/contest/1209/problem/G1 题意:给你一个序列,要你进行一些操作后把他变成一个好序列,好序列的定义是,两个相同的数中间的数都要与他相同 ...

  6. numpy.bincount()

    numpy.bincount详解 numpy.bincount(x, weights=None,minlength=0) 参数中要求x是一个array_like,一维的并且包含非负整数. In [19 ...

  7. DS博客作业8——课程总结

    1.当初你是如何做出选择计算机专业的决定的? 本来我在集美大学第一志愿专业是理学院的数据科学与大数据,奈何隔壁县城小伙伴比我高了2分,我就来到了网络,但经过我和她的交流,我意识到我们的课程差不多,同样 ...

  8. 【攻克RabbitMQ】常见问题

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/zlt995768025/article/ ...

  9. legend3---lavarel常用artisan命令操作

    legend3---lavarel常用artisan命令操作 一.总结 一句话总结: 帮助:php artisan可以调出帮助命令 1.npm安装后盾js? npm install hdjs node ...

  10. opencart升级 各种坑 没有主题,没有扩展,权限等问题

    1.后台导航菜单没有扩展功能(扩展不显示) 2.只要是报错显示DIR_XXXX  基本都是config.php 和  admin/config.php  这两配置文件有关 我这问题是config.ph ...