这道题用构造法, 就是自己依据题目想出一种可以得到解的方法, 没有什么规律可言, 只能根据题目本身来思考. 这道题的构造法比较复杂, 不知道刘汝佳是怎么想出来的, 我想的话肯定想不到. 具体思路紫书上讲得非常清楚了, 就不讲了.代码有详细注释 #include<cstdio> #include<vector> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namespace std; const int M…
题意:就是给出一个字符串,让你去一个一个猜测,相同字母算一次,如果是之前猜过的也算错,如果你在错7次前猜对就算你赢,文章中是LRJ的例题代码. #include<stdio.h> #include<string.h> #define maxn 100 int left, chance; char s[maxn], s2[maxn]; int win, lose; void guess(char ch) { int bad = 1; for(int i = 0; i < str…
就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去看他的代码发现他的代码和他讲的是两回事 他的代码里直接是枚举a和b,不是按照书上的思路来的. 有点迷 #include<iostream> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namespace std; con…
Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping. The most popular ciphers…
题意: n个人围成个圆,从1到n,一个人从1数到k就让第k个人离场,了另一个人从n开始数,数到m就让第m个人下去,直到剩下最后一个人,并依次输出离场人的序号. 水题,直接上标程了 #include<stdio.h> #define maxn 25 int n, k, m, a[maxn]; // 逆时针走t步,步长是d(-1表示顺时针走),返回新位置 int go(int p, int d, int t) { while(t--) { do { p = (p+d+n-1) % n + 1; }…
Some DNA sequences exist in circular forms as in the following gure, which shows a circular sequence \CGAGTCAGCT", that is, the last symbol \ T " in \ CGAGTCAGCT " is connected to the rst symbol \ C ". We al- ways read a circular seque…
For a positive integer N , the digit-sum of N is defined as the sum of N itself and its digits. When M is the digitsum of N , we call N a generator of M . For example, the digit-sum of 245 is 256 (= 245 + 2 + 4 + 5). Therefore, 245 is a generator of…
MasterMind is a game for two players. One of them, Designer, selects a secret code. The other, Breaker, tries to break it. A code is no more than a row of colored dots. At the beginning of a game, the players agree upon the length N that a code must…
A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string is read from ri…
A common typing error is to place the hands on the keyboard one row to the right of the correct position. So "Q" is typed as "W" and "J" is typed as "K" and so on. You are to decode a message typed in this manner. I…
TeX is a typesetting language developed by Donald Knuth. It takes source text together with a few typesetting instructions and produces, one hopes, a beautiful document. Beautiful documents use `` and " to delimit quotations, rather than the mundane…
这道题方法非常的巧妙, 两层的n*n, 第一层第I行全是第I个国家, 第二层的第j列全是第j个国家.这样能符合题目的条件.比如说第1个国家, 在第一层的第一行全是A, 然后在第二层的第一行就有ABCDE--这样A就和所有的国家都连接了,其他国家也是一样的.只能说这种方法非常巧妙吧,答案讲出来很简单,但是不容易想到. #include<cstdio> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namespace st…
#include<cstdio> #include<iostream> #include<sstream> #include<algorithm> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namespace std; const int MAXN = 50; int a[MAXN], n; void filp(int pos) //学习这里翻转的写法 { REP(i, 0, p…
解法和合并果子是一样的, 每次取最小的两个, 更新答案, 加入队列 #include<cstdio> #include<queue> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namespace std; int main() { int n, x; while(~scanf("%d", &n) && n) { priority_queue<int, v…
这道题用到了等价转换的思想 所有要运到a1的酒, 都要经过a2, 所以不如把a2的值改成a1+a2,然后依次以此类推. #include<cstdio> #include<cmath> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namespace std; int main() { int n; while(~scanf("%d", &n) && n) { l…