CodeForces 570B,C
来源:互联网 发布:linux tcp连接日志 编辑:程序博客网 时间:2024/05/01 13:46
CodeForces 570B
题意:给定n和m,然后再(1-n)中随机取出c,求一个m使得 的概率最大,概率一样时输出最小的m。
思路:只需要看1到m-1和m+1和n的最大的那一边就可以了,坑是n=1的情况和n为奇数m为n/2+1的情况要特判。
code:
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <sstream>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef long double ld;const int INF=0x3fffffff;const int inf=-INF;const int N=1e5+5;const int M=2005;const int mod=1000000007;const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x))#define cpy(x,a) memcpy(x,a,sizeof(a))#define ft(i,s,n) for (int i=s;i<=n;i++)#define frt(i,s,n) for (int i=s;i>=n;i--)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define lrt rt<<1#define rrt rt<<1|1#define middle int m=(r+l)>>1#define lowbit(x) (x&-x)#define pii pair<int,int>#define mk make_pair#define IN freopen("in.txt","r",stdin);#define OUT freopen("out.txt","w",stdout);int main(){ int n,m; scanf("%d %d",&n,&m); if (n==1) puts("1"); else { if (m-1>n-m) printf("%d\n",m-1); else if (n%2==1&&m==n/2+1) printf("%d\n",m-1); else printf("%d\n",m+1); }}
CodeForces 570C
题意:给定一个n的字符的字符串,然后有m个修改,对于每次修改,询问字符串中有连续。。的个数。
思路:一开始先统计一下个数,然后对于每次修改,最多可修改2个个数。然后分情况讨论就可以。
code:
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <sstream>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef long double ld;const int INF=0x3fffffff;const int inf=-INF;const int N=3e5+5;const int M=2005;const int mod=1000000007;const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x))#define cpy(x,a) memcpy(x,a,sizeof(a))#define ft(i,s,n) for (int i=s;i<=n;i++)#define frt(i,s,n) for (int i=s;i>=n;i--)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define lrt rt<<1#define rrt rt<<1|1#define middle int m=(r+l)>>1#define lowbit(x) (x&-x)#define pii pair<int,int>#define mk make_pair#define IN freopen("in.txt","r",stdin);#define OUT freopen("out.txt","w",stdout);char s[N];int sol(int p,int c){ if (c=='.'&&s[p]!='.'){ s[p]=c; if (s[p-1]=='.'&&s[p+1]=='.') return 2; if (s[p-1]=='.'||s[p+1]=='.') return 1; return 0; } if (c!='.'&&s[p]=='.'){ s[p]=c; if (s[p-1]=='.'&&s[p+1]=='.') return -2; if (s[p-1]=='.'||s[p+1]=='.') return -1; return 0; } return 0;}int main(){ int n,k,p,t=0; scanf("%d %d",&n,&k); scanf("%s",s+1);s[0]='#'; ft(i,1,n) if(s[i]=='.'&&s[i-1]=='.') t++; ft(i,1,k){ char ch[2]; scanf("%d %s",&p,&ch); t+=sol(p,ch[0]); printf("%d\n",t); }}
0 0
- CodeForces 570B,C
- codeforces 282 A B C
- Codeforces 300-A/B/C
- codeforces 124B、124C
- CodeForces 560A,B,C
- CodeForces 572A,B,C
- CodeForces 707-A,B,C
- Codeforces 371 A,B,C
- codeforces-757-【B、C思维】
- codeforces-758【B、C思维】
- codeforces 791B 791 C
- codeforces 883C. Downloading B++
- Codeforces 570B
- Codeforces Beta Round #1 A B C
- CodeForces#211(Div.2) - A,B,C
- Codeforces Beta Round #1 A B C
- Codeforces Beta Round #2 A B C
- Codeforces 228 div2 A,B,C
- 用logrotate管理每日增长的日志
- 华为oj:图片管理
- 腾讯分析系统架构解析
- Android —— Studio导入Eclipse项目方法以及出现的问题
- Java构造函数 为什么需要无参构造函数
- CodeForces 570B,C
- Android自定义控件_垂直滚动器PickerView
- 主队列中添加的同步操作永远不会被执行,会死锁原因
- Android gradient设置布局的背景渐变效果
- 探真无阻塞加载javascript脚本技术,我们会发现很多意想不到的秘密
- spark aggregateByKey函数使用问题
- Android SDK Manager 更新代理配置和代理清单
- 802.11协议帧格式、Wi-Fi连接交互过程、无线破解入门研究
- Fiddler转发请求与修改响应