Codeforces Round #589 (Div. 2) (e、f没写)

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

A. Distinct Digits

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

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 bool check(int n){
 4     int vis[15]={0};
 5     while(n){
 6         if(!vis[n%10])  vis[n%10]=1;
 7         else return false;
 8         n/=10;
 9     }
10     return true;
11 }
12 int main()
13 {
14     int l,r;
15     cin>>l>>r;
16     for(int i = l;i <=r;++i){
17         if(check(i)){
18             cout<<i<<endl;return 0;
19         }
20     }
21     cout<<"-1"<<endl;
22     return 0;
23 }

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可填黑可填白)

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const ll mod = 1e9+7;
 5 int mp[1005][1005];
 6 long long power(long long a,long long b)///a是底数,b是次幂
 7 {
 8     long long ans=1;
 9     for(;b!=0;b>>=1)
10     {
11         if(b&1) ans=(long long)ans*a%mod;
12         a=(long long)a*a%mod;
13     }
14     return ans;
15 }
16
17 int main()
18 {
19    int n,m;
20    cin>>n>>m;
21    for(int i=1;i<=n;i++)
22    {
23        int a;cin>>a;
24        for(int j=1;j<=a;j++)
25        {
26            mp[i][j]=1;
27        }
28        mp[i][a+1]=-1;
29    }
30    int f=0;
31    for(int i=1;i<=m;i++)
32    {
33        int a;cin>>a;
34        for(int j=1;j<=a;j++)
35        {
36            if(mp[j][i]==-1) f=1;
37            mp[j][i]=1;
38        }
39        if(mp[a+1][i]==1) f=1;
40        mp[a+1][i]=-1;
41    }
42    if(f==1)
43     cout<<0<<endl;
44    else
45    {
46        int ans=0;
47        for(int i=1;i<=n;i++)
48         for(int j=1;j<=m;j++)
49         if(mp[i][j]==0)
50         ans++;
51        cout<<power(2,ans)<<endl;
52    }
53 }

AC代码

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

C. Primes and Multiplication

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

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

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

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const ll mod = 1e9+7;
 5 ll sq(ll a,ll b){
 6     ll cnt=1;
 7     while(b){
 8         if(b&1)cnt=cnt%mod*a%mod;
 9         a=a*a%mod;
10         b>>=1;
11     }
12     return cnt%mod;
13 }
14 vector<ll>s;
15 int main(){
16     ll ans= 1,x,n;
17         cin>>x>>n;
18     for(ll i = 2;i *i<= x;++i){
19         if(x%i==0)s.push_back(i);
20         while(x%i==0)x/=i;
21     }
22     s.push_back(x);
23     for(int i = 0;i< s.size();++i){
24         if(s[i]==1) continue;
25         ll sum=0,temp=s[i],a=s[i];
26         while(temp<=n){
27             sum+=n/temp;
28             if(temp>n/a)break;
29             temp*=a;
30         }
31
32         ans=ans*sq(a,sum)%mod;ans%=mod;
33     }
34     cout<<ans<<endl;
35     return 0;
36 }

AC代码

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

D. Complete Tripartite

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

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

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

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

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N = 1e5+3;
 4 vector<int>s[N];
 5 int pre[N],cnt1=0,cnt2=0,cnt3=0,temp1,temp2,temp3;
 6 struct ac{
 7     int x,y;
 8 }a[350000];
 9 int main()
10 {
11     int n,m;
12     cin>>n>>m;
13     for(int i = 1;i <=n;++i)pre[i]=1;cnt1=n;
14     for(int i = 0;i <m;++i){
15         cin>>a[i].x>>a[i].y;
16         s[a[i].x].push_back(a[i].y);s[a[i].y].push_back(a[i].x);
17     }
18
19     for(int i = 1;i <= n; ++i){
20         if(s[i].size()<2){cout<<"-1"<<endl;return 0;}
21         for(int j = 0;j < s[i].size();++j){
22             if(pre[i]==1)
23                 if(pre[s[i][j]]==1)pre[s[i][j]]=2,cnt1--,cnt2++;
24         }
25     }
26     for(int i = 1;i <= n;++i){
27         for(int j = 0;j <s[i].size();++j){
28             if(pre[i]==2)
29                 if(pre[s[i][j]]==2)pre[s[i][j]]=3,cnt2--,cnt3++;
30         }
31     }
32     if(cnt1==0||cnt2==0||cnt3==0){
33         cout<<"-1"<<endl;return 0;
34     }
35
36     for(int i = 1;i <=n;++i){
37         temp1=temp2=temp3=0;
38         for(int j = 0;j < s[i].size();++j){
39             if(pre[i]==pre[s[i][j]]){
40                 cout<<"-1"<<endl;return 0;
41             }
42             if(pre[i]==1){
43                 if(pre[s[i][j]]==2)temp2++;
44                 else if(pre[s[i][j]]==3)temp3++;
45             }
46             else if(pre[i]==2){
47                 if(pre[s[i][j]]==1)temp1++;
48                 else if(pre[s[i][j]]==3)temp3++;
49             }
50             else if(pre[i]==3){
51                 if(pre[s[i][j]]==2)temp2++;
52                 else if(pre[s[i][j]]==1)temp1++;
53             }
54         }
55         if(pre[i]==1){
56                 if(temp2<cnt2||temp3<cnt3){
57                         cout<<"-1"<<endl;return 0;
58                 }
59             }
60         else if(pre[i]==2){
61                 if(temp1<cnt1||temp3<cnt3){
62                         cout<<"-1"<<endl;return 0;
63                 }
64             }
65         else if(pre[i]==3){
66                 if(temp2<cnt2||temp1<cnt1){
67                         cout<<"-1"<<endl;return 0;
68                 }
69             }
70     }
71     for(int i = 1;i <=n;++i)cout<<pre[i]<<" ";cout<<endl;
72 }

AC代码

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

原文地址:https://www.cnblogs.com/h404nofound/p/11617631.html

时间: 2024-07-30 09:33:32

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

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\)的格子中填入\([1,k]\)之间的数字,并且保证每一行至少有一个\(1\),每一列至少有一个\(1\),问有多少种满足条件的填充方案. [Solution] 令\(R[i]\)表示为第\(i\)行至少有一个\(1\)的方案数,\(C[i]\)表示第\(i\)列至少有一个\(1\)的方案数.则题目要

Codeforces Round #589 (Div. 2) B——B. Filling the Grid

Suppose there is a h×wh×w grid consisting of empty or full cells. Let's make some definitions: riri is the number of consecutive full cells connected to the left side in the ii-th row (1≤i≤h1≤i≤h). In particular, ri=0ri=0 if the leftmost cell of the 

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

目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路) F.Asya And Kittens(链表) G.Most Dangerous Shark Codeforces 1131 比赛链接 hack一个暴力失败了两次最后还是没成功身败名裂= = CF跑的也太快了吧... 不过倒也涨了不少. A.Sea Battle //想麻烦了,但是无所谓... #

Codeforces Round 589 (Div. 2) 题解

Is that a kind of fetishism? No, he is objectively a god. 见识了一把 Mcdic 究竟出题有多神. (虽然感觉还是吹过头了) 开了场 Virtual 玩. 开场先秒了 AB.C 居然差点没做出来,有点耻辱. 开 D.怎么不会--Div. 2 的 D 都能卡住我,我心态崩了. 调到 E. woc 这不是 sb 题吗-- 回来肝 D.想了想口胡出来了,然而心态已经崩了,用了很长很长时间才打出来. 最后只剩 20min 时开 F.这--辣鸡三合

Codeforces Round #496 (Div. 3)A~F

(寒假训练赛,也是lj难得补完的一场 https://codeforces.com/contest/1005 A.题意是  每一个楼梯有x个台阶,小女孩爬楼的时候会从1开始数每层楼有几个台阶,现在给给出n个数字a1~an,代表着小女孩爬楼时数数的序列,求有多少层楼梯,并且输出每层楼梯台阶数. 解法:for循环模拟小女孩从1开始数,数到下一个1的话楼层++,然后把他前一个数存进去. int now = 0; for(int i = 0;i < n;++i){ cin>>a; if(a ==

Codeforces Round #589 (Div. 2)

目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Complete Tripartite E. Another Filling the Grid Contest Info Practice Link Solved A B C D E F 5/6 O O O O ? - O 在比赛中通过 ? 赛后通过 ! 尝试了但是失败了 - 没有尝试 Solutions

Codeforces Round #516 (Div. 2) (A~F)

目录 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Labyrinth(BFS) E.Dwarves,Hats and Extrasensory Abilities(交互 二分) D.Labyrinth E.Dwarves,Hats and Extrasensory Abilities 比赛链接 A.Make a triangle! 不放了. B.Equations of Mathema

Codeforces Round #589 (Div. 2) - C

题目大意:$prime(x)$ 代表 $x$ 的质因数的集合. $g(x, p)$ 代表 $p^k$ 的最大值, $k$ 为整数,并且 $x$ 可以被 $p^k$ 整除. $f(x, p)$ 代表 对于 $prime(x)$ 中的每一个 $x$ 的 $g(x, p)$ 值. 现在给定 $x, n$ 求 $f(x, 1) * f(x, 2) * ... *f(x, n) mod (10^9 + 7)$ 的值. 思路:对于 $x$ 进行质因数分解,分别考虑每一个 $prime(x)$ 对答案做出的贡

Codeforces Round #589 div.2 C,D

感觉这一场的复杂度非常的玄学... 也可能是我偷懒太长时间变菜了QAQ. C 题意: 给出\(x,n\),求x质因子的从1到n的g(i,p)的连乘 思路: 求出x的每个质因子,直接连乘到n计算即可. #include<bits/stdc++.h> #define ll long long using namespace std; typedef pair<int,int> pii; typedef vector<int> VI; vector<int> pr