Created
November 3, 2013 15:09
-
-
Save zsh-89/7291216 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
int n, k; | |
scanf("%d %d", &n, &k); | |
n *= 2; | |
for (int i = 1; i <= n; i+=2) { | |
if (k) { | |
--k; | |
printf("%d %d ", i, i+1); | |
} else | |
printf("%d %d ", i+1, i); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
有个更贪心的办法:
首先,如果要凑0,只要保证全部 ai > ai+1 或全部 ai < ai+1即可
如果要凑2,
2=4-2=(3+1)-(3-1)=|4-1| + |2-3| - |4-1+2-3|
4=8-4=(6+2)-(6-2)= ....
....
但是数字会越界,而且凑满接下来的0编程不方便。
这道题就是很考观察了,很有趣!