Codeforces Round #257 (Div. 2)

https://codeforces.com/contest/450/

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 n,m;
24 int a[105];
25
26 int main(){
27     #ifndef ONLINE_JUDGE
28      //   freopen("1.txt","r",stdin);
29     #endif
30     cin>>n>>m;
31     for(int i=0;i<n;i++){
32         cin>>a[i];
33     }
34     int pos=0;
35     int i=0;
36     int co=0;
37     while(1){
38         if(a[i]>0){
39             pos=i;
40             a[i]-=min(m,a[i]);
41             co=0;
42         }
43         else {
44             co++;
45         }
46         i=(i+1)%n;
47         if(co==n) break;
48     }
49     cout<<pos+1<<endl;
50
51 }

View Code

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 ll n,m,k;
23 struct sair{
24     ll a[3][3];
25     sair(){
26         a[0][0]=0,a[0][1]=0;
27         a[1][0]=0,a[1][1]=0;
28     }
29     friend sair operator*(const sair&a,const sair &b){
30         sair ans;
31         for(int i=0;i<2;i++){
32             for(int j=0;j<2;j++){
33                 for(int k=0;k<2;k++){
34                     ans.a[i][j]=(ans.a[i][j]+a.a[i][k]*b.a[k][j]%mod+mod)%mod;
35                 }
36             }
37         }
38         return ans;
39     }
40 };
41
42 sair pow_mul(sair a){
43     k-=2;
44     sair base;
45     base.a[0][0]=1,base.a[0][1]=0;
46     base.a[1][0]=0,base.a[1][1]=1;
47     while(k){
48         if(k&1)
49             base=base*a;
50         k>>=1;
51         a=a*a;
52     }
53     return base;
54 }
55
56 int main(){
57     #ifndef ONLINE_JUDGE
58      //   freopen("1.txt","r",stdin);
59     #endif
60     cin>>n>>m>>k;
61     sair a;
62     a.a[0][0]=(m+mod)%mod,a.a[0][1]=0;
63     a.a[1][0]=(n+mod)%mod,a.a[1][1]=0;
64     if(k==1) cout<<a.a[1][0]<<endl;
65     else if(k==2) cout<<a.a[0][0]<<endl;
66     else {
67         sair base;
68         base.a[0][0]=1,base.a[0][1]=-1;
69         base.a[1][0]=1,base.a[1][1]=0;
70         sair tmp=pow_mul(base);
71         base=tmp*a;
72         cout<<(base.a[0][0]+mod)%mod<<endl;
73     }
74
75 }

View Code

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 main(){
24     #ifndef ONLINE_JUDGE
25      //   freopen("1.txt","r",stdin);
26     #endif
27     ll n,m,k;
28     cin>>n>>m>>k;
29     ll tmp=(n-1)+(m-1);
30     if(n-1==0) tmp=m-1;
31     if(m-1==0) tmp=n-1;
32     if(n-1==0&&m-1==0) tmp=0;
33     if(tmp<k) cout<<-1<<endl;
34     else{
35         ll ans=0;
36         if(k>=n)ans=max(ans,m/(k-n+2));
37         if(k>=m)ans=max(ans,n/(k-m+2));
38         if(k<n)ans=max(ans,m*(n/(k+1)));
39         if(k<m)ans=max(ans,n*(m/(k+1)));
40         cout<<ans<<endl;
41     }
42
43 }

View Code

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 n,m,k;
 24 vector<pli>ve[200005];
 25 ll dis[200005];
 26 bool book[200005];
 27 bool vis[200005];
 28 int ans;
 29 int co;
 30 void Dijstra(){
 31     priority_queue<pli,vector<pli>,greater<pli> >Q;
 32     dis[1]=0;
 33     int flag;
 34     Q.push({0,1});
 35     for(int i=0;i<=n;i++){
 36         if(book[i]==1){
 37             Q.push({dis[i],i});
 38         }
 39     }
 40     while(!Q.empty()){
 41         pli s=Q.top();
 42         Q.pop();
 43         int pos=s.second;
 44         if(!vis[pos]){
 45             vis[pos]=1;
 46             for(int i=0;i<ve[pos].size();i++){
 47                 flag=0;
 48                 int u=ve[pos][i].second;
 49                 ll len=ve[pos][i].first;
 50                 if(dis[u]>=dis[pos]+len){
 51                     if(dis[u]==dis[pos]+len){
 52                         flag=1;
 53                     }
 54                     dis[u]=dis[pos]+len;
 55                     if(book[u]){
 56                         ans++;
 57                         book[u]=0;
 58                     }
 59                     if(!flag) Q.push({dis[u],u});
 60                 }
 61             }
 62         }
 63     }
 64     for(int i=0;i<=n;i++){
 65         k-=book[i];
 66     }
 67     cout<<k<<endl;
 68 }
 69
 70 int main(){
 71     #ifndef ONLINE_JUDGE
 72      //   freopen("1.txt","r",stdin);
 73     #endif
 74     cin>>n>>m>>k;
 75     int u,v;
 76     ll c;
 77     for(int i=0;i<=n;i++){
 78         dis[i]=0x3f3f3f3f3f3f3f3f;
 79         vis[i]=0;
 80         book[i]=0;
 81     }
 82     for(int i=1;i<=m;i++){
 83         cin>>u>>v>>c;
 84         ve[u].pb({c,v});
 85         ve[v].pb({c,u});
 86     }
 87     for(int i=1;i<=k;i++){
 88         cin>>u>>c;
 89         if(dis[u]>c){
 90             dis[u]=c;
 91             if(!book[u]){
 92                 book[u]=1;
 93             }
 94             else{
 95                 ans++;
 96             }
 97         }
 98         else{
 99             ans++;
100         }
101     }
102     Dijstra();
103     //cout<<ans<<endl;
104
105 }

View Code

E

模拟题+数论

 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 vector<int> a[maxn],ans;
23 bool book[maxn];
24
25 int main(){
26     #ifndef ONLINE_JUDGE
27      //   freopen("1.txt","r",stdin);
28     #endif
29     int n;
30     cin>>n;
31     if(n==1){
32         cout<<0;
33         return 0;
34     }
35     for(int i=3;i<=n;i++){
36         if((i%2==1)&&book[i]==0 ){
37             for(int j=i;j<=n;j+=i){
38                 if(book[j]==0){
39                     a[i].push_back(j);
40                     book[j]=1;
41                 }
42
43             }
44         }
45     }
46     for(int i=3;i<=(n/2);i++){
47         if(a[i].size()>0){
48             if(a[i].size()%2==1){
49                 a[i].erase(a[i].begin()+1);
50                 book[2*i]=0;
51             }
52             while(a[i].size()>0){
53                 ans.push_back(a[i].back());
54                 a[i].pop_back();
55             }
56         }
57     }
58     for(int i=2 ; i<=n ; i+=2){
59         if(book[i]==0){
60             a[2].push_back(i);
61         }
62     }
63     for(int i=0;i<a[2].size()-1;i+=2){
64         ans.push_back(a[2][i]);
65         ans.push_back(a[2][i+1]);
66     }
67     int answer=(ans.size()>>1);
68     cout<<answer<<endl;
69     for(int i=ans.size()-1;i>=0;i-=2){
70         cout<<ans[i]<<" "<<ans[i-1]<<endl;
71     }
72 }

View Code

转载于:https://www.cnblogs.com/Fighting-sh/p/10541826.html

Codeforces Round #257 (Div. 2)相关推荐

  1. Codeforces Round #257 (Div. 1) D. Jzzhu and Numbers 高维前缀和 + 容斥

    传送门 文章目录 题意: 思路: 题意: 思路: 完全想不到容斥啊,看了半天也没看懂渍渍渍. 定义f[i]f[i]f[i]表示iii的超集个数,那么选择的方案就是2f[i]−12^{f[i]}-12f ...

  2. Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences

    B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #257 (Div. 2) C. Jzzhu and Chocolate

    C. Jzzhu and Chocolate time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. hash+set Codeforces Round #291 (Div. 2) C. Watto and Mechanism

    题目传送门 1 /* 2 hash+set:首先把各个字符串的哈希值保存在set容器里,然后对于查询的每一个字符串的每一位进行枚举 3 用set的find函数查找是否存在替换后的字符串,理解后并不难. ...

  5. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  6. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  7. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  8. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  9. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

最新文章

  1. RabbitMQ入门(4)--路由
  2. 带AM或者PM的时间字符串转data类型
  3. java ubuntu 14.04,Ubuntu 14.04安装java的方法
  4. Google 系两公司联手,要让无人车少“犯错”
  5. 科普 | 12个关键词,告诉你到底什么是机器学习
  6. Hitpoint:外贸企业如何选择合适的ERP系统
  7. PHP实例——获取文件的绝对路径
  8. html圆角边框只有左边,border-radius以外的CSS圆角边框制作方法
  9. 加加速度matlab,关于加加速度的若干机械运动分析及MATLAB模拟
  10. [CTO札记]Google数字图书馆对中国版权的威胁
  11. 【Jenkins】Jenkins : Mac中Jenkins的停止和启动
  12. poj 1155 TELE
  13. 企业付款php 接口,微信企业付款接口PHP开发需要注意的两个地方
  14. request重定向_Python转发与重定向
  15. 变量声明提升和函数声明提升
  16. 各版本JQuery文件下载
  17. html实现word分页符,word分页-解析Word——自动分页符与手动分页符
  18. 通达OA11.0 补丁文件
  19. python 档案管理系统_用Python编写人才档案管理系统?
  20. PCQQ - 发送自定义的XML卡片消息

热门文章

  1. 新手从零入手 JQuery 【看这篇】
  2. 用 Python制作解压缩软件,其实特简单
  3. 使按钮变灰不可用方法
  4. 数学模型奶制品生产c语言编程,数学模型 奶制品的生产与销售.ppt
  5. 教师计算机提升返岗总结,语文老师返岗研修心得体会
  6. PictureMerge
  7. 第十二届蓝桥杯 ——双阶乘
  8. 20221217英语学习
  9. HbuilderX连接小米手机/运行到小程序
  10. (附源码)基于Python的“书怡”在线书店系统的设计与实现 毕业设计082332