Codeforces Round #450 (Div. 2)

Codeforces Round #450 (Div. 2)

http://codeforces.com/contest/900

A

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 100005
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef pair<int,int> pii;
14 typedef pair<long long,int>pli;
15 typedef pair<int,char> pic;
16 typedef pair<pair<int,string>,pii> ppp;
17 typedef unsigned long long ull;
18 const long long MOD=1e9+7;
19 /*#ifndef ONLINE_JUDGE
20         freopen("1.txt","r",stdin);
21 #endif */
22
23 int a[2];
24 int main(){
25     #ifndef ONLINE_JUDGE
26      //   freopen("1.txt","r",stdin);
27     #endif
28     std::ios::sync_with_stdio(false);
29     int n;
30     cin>>n;
31     int u,v;
32     for(int i=0;i<n;i++){
33         cin>>u>>v;
34         if(u>0) a[0]++;
35         else a[1]++;
36     }
37     if(a[0]<=1||a[1]<=1) cout<<"YES"<<endl;
38     else cout<<"NO"<<endl;
39 }

B

模拟除法

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 100005
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef pair<int,int> pii;
14 typedef pair<long long,int>pli;
15 typedef pair<int,char> pic;
16 typedef pair<pair<int,string>,pii> ppp;
17 typedef unsigned long long ull;
18 const long long MOD=1e9+7;
19 /*#ifndef ONLINE_JUDGE
20         freopen("1.txt","r",stdin);
21 #endif */
22
23 int a[2];
24 ll fac[15];
25 int main(){
26     #ifndef ONLINE_JUDGE
27      //   freopen("1.txt","r",stdin);
28     #endif
29     int a,b,c;
30     cin>>a>>b>>c;
31     int co=1;
32     while(1){
33         a*=10;
34         int k=a/b;
35         a%=b;
36         if(k==c){
37             cout<<co<<endl;
38             return 0;
39         }
40         co++;
41         if(co>=100000) break;
42     }
43     cout<<-1<<endl;
44
45 }

C

找规律

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 100005
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef pair<int,int> pii;
14 typedef pair<long long,int>pli;
15 typedef pair<int,char> pic;
16 typedef pair<pair<int,string>,pii> ppp;
17 typedef unsigned long long ull;
18 const long long MOD=1e9+7;
19 /*#ifndef ONLINE_JUDGE
20         freopen("1.txt","r",stdin);
21 #endif */
22
23 int n;
24 int a[maxn],cnt[maxn];
25
26 int main(){
27     #ifndef ONLINE_JUDGE
28      //   freopen("1.txt","r",stdin);
29     #endif
30     cin>>n;
31     int max1=0,max2=0;
32     for(int i=1;i<=n;i++) cin>>a[i];
33     for(int i=1;i<=n;i++){
34         if(a[i]>max1){
35             max2=max1;
36             max1=a[i];
37             cnt[a[i]]--;
38         }
39         else if(a[i]>max2){
40             cnt[max1]++;
41             max2=a[i];
42         }
43     }
44     int max3=-maxn,ans;
45     for(int i=1;i<=n;i++){
46         if(cnt[i]>max3){
47             max3=cnt[i];
48             ans=i;
49         }
50     }
51     cout<<ans<<endl;
52
53 }

D

记忆化搜索+容斥

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 100005
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef pair<int,int> pii;
14 typedef pair<long long,int>pli;
15 typedef pair<int,char> pic;
16 typedef pair<pair<int,string>,pii> ppp;
17 typedef unsigned long long ull;
18 const long long MOD=1e9+7;
19 /*#ifndef ONLINE_JUDGE
20         freopen("1.txt","r",stdin);
21 #endif */
22
23 int x,y;
24 map<int,int>mp;
25
26 ll pow_mul(ll a,ll b){
27     ll ans=1;
28     while(b){
29         if(b&1) ans=(ans*a)%MOD;
30         b>>=1;
31         a=(a*a)%MOD;
32     }
33     return ans;
34 }
35
36 ll dp(int x){
37     if(x==1) return 1;
38     if(mp.count(x)) return mp[x];
39     mp[x]=pow_mul(2,x-1);
40     for(int i=2;i*i<=x;i++){
41         if(x%i==0){
42             mp[x]=(mp[x]-dp(x/i)+MOD)%MOD;
43             if(i!=x/i){
44                 mp[x]=(mp[x]-dp(i)+MOD)%MOD;
45             }
46         }
47     }
48     return mp[x]=(mp[x]-dp(1)+MOD)%MOD;
49 }
50
51 int main(){
52     #ifndef ONLINE_JUDGE
53      //   freopen("1.txt","r",stdin);
54     #endif
55     cin>>x>>y;
56     if(y%x){
57         cout<<0<<endl;
58     }
59     else{
60         cout<<dp(y/x)<<endl;
61     }
62
63 }

E

DP

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 100005
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef pair<int,int> pii;
14 typedef pair<long long,int>pli;
15 typedef pair<int,char> pic;
16 typedef pair<pair<int,string>,pii> ppp;
17 typedef unsigned long long ull;
18 const long long MOD=1e9+7;
19 /*#ifndef ONLINE_JUDGE
20         freopen("1.txt","r",stdin);
21 #endif */
22 pii d[maxn];
23 int f[3][maxn], n, m, b[maxn];
24 char a[maxn];
25
26 int main(){
27     #ifndef ONLINE_JUDGE
28      //   freopen("1.txt","r",stdin);
29     #endif
30      cin >> n;
31     for (int i = 1; i <= n; i++)
32         cin >> a[i];
33     cin >> m;
34     for (int i = 1; i <= n; i++)
35     {
36         if (a[i] == ‘?‘)
37             b[i] = b[i-1] + 1;
38         else b[i] = b[i-1];
39         if (a[i] != ‘a‘)
40             f[1][i] = f[0][i-1]+1;
41         if (a[i] != ‘b‘)
42             f[0][i] = f[1][i-1]+1;
43         if (f[!(m&1)][i] >= m)
44             d[i] = {d[i-m].first + 1, -(b[i]-b[i-m]-d[i-m].second)};
45         d[i] = max(d[i-1], d[i]);
46     }
47     cout << - d[n].second;
48
49 }

原文地址:https://www.cnblogs.com/Fighting-sh/p/10538681.html

时间: 2024-11-06 03:47:11

Codeforces Round #450 (Div. 2)的相关文章

Codeforces Round #450 (Div. 2) ABCD

这次还是能看的0 0,没出现一题掉分情况. QAQ前两次掉分还被hack了0 0,两行清泪. A. Find Extra One You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis. Input

Codeforces Round #450 (Div. 2)ABC

A. Find Extra One You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis. Input The first line contains a single positive inte

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除

Codeforces Round #339 (Div. 2) B. Gena&#39;s Code

B. Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, f

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un