思路:把n分成[1,n/2],[n/2+1,n],假设m在左区间.a=m+1,假设m在右区间,a=m-1.可是我居然忘了处理1,1这个特殊数据.被人hack了. 总结:下次一定要注意了,提交前一定要看下边界数据,不要急着交. 题目链接:http://codeforces.com/problemset/problem/570/B <pre name="code" class="cpp">#include<bits/stdc++.h> using…
题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; +; int n, m; int main() { while( ~scanf("%d %d", &n, &m ) ) { ) { printf("1\n"); continue; } ) printf( ); else…
贪心,如果m分成的两个区间长度不相等,那么选长的那个区间最接近m的位置,否则选m-1位置,特判一下n等于1的情况 #include<bits/stdc++.h> using namespace std; int main() { int n,m; scanf("%d%d",&n,&m); ){ printf(; } , d2 = n-m; if(d1<d2){ printf(); }else { printf(); } ; }…
B. Simple Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let'…
C. Replacement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem/C Description Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replac…
C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem/C Description Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replace…
A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many peopl…
B. Simple Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let'…
A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序),第一位获得胜利. 求最后选举获胜者. 思路: 直接模拟就可以. 代码: /* * @author FreeWifi_novicer * language : C++/C */ #include<cstdio> #include<iostream> #include<cstrin…
题意:给定一个字符串,里面有各种小写字母和' . ' ,无论是什么字母,都是一样的,假设遇到' . . ' ,就要合并成一个' .',有m个询问,每次都在字符串某个位置上将原来的字符改成题目给的字符,问每次须要多少次合并次数.才使字符串没有' .. ' 思路:最原始的想法,就是对于每一次询问,都遍历整个字符串.这样时间复杂度o(n*m),就高达10^10方,非常明显会tle. 换下思路,事实上每次询问所改变的字符都会保留到下一次.也就是下一次的次数就会受到上一次的影响,那么我仅仅要就算出第一次的…