Educational Codeforces Round 43 Editorial
A.Minimum Binary Number
思路:很明显关键在于有多少个0。如果没有0,最后就是1,不然的话如果输入的数是0,输出也为0,其他的时候就是在一堆零的前面加一个1。
代码:
#include<iostream> #include<cstdio> using namespace std; int main(){ int n; string s; cin>>n>>s; if(n == 1) { cout<<s<<endl; } else { int tmp = 0; for(int i = 0; i < n; i++) { if(s[i] == '0') tmp++; } cout << "1"; for(int i = 0; i < tmp; i++) cout << "0"; cout << endl; } return 0; }B.Lara Croft and the New Game
思路:也是挺水的一道数学题。关键在于发现从下往上转弯开始每行的格子数都相同。数学大法好。
代码:
#include<iostream> #include<cstdio> using namespace std; int main(){ long long n, m, k; scanf("%lld%lld%lld", &n, &m, &k); if(k >= 0 && k <= n - 1) { printf("%lld 1\n", k + 1); } else { long long row = (k - n) / (m - 1); printf("%lld ", (n - row)); if(row & 1)//如果是从下往上的奇数行 { printf("%lld\n", m - (k - n) % (m - 1) ); } else { printf("%lld\n", 2 + (k - n) % (m - 1) ); } } return 0; }