Skip to content

Instantly share code, notes, and snippets.

@zsh-89
Created November 3, 2013 15:09
Show Gist options
  • Save zsh-89/7291216 to your computer and use it in GitHub Desktop.
Save zsh-89/7291216 to your computer and use it in GitHub Desktop.
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;
}
@zsh-89
Copy link
Author

zsh-89 commented Nov 3, 2013

有个更贪心的办法:
首先,如果要凑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编程不方便。

这道题就是很考观察了,很有趣!

@eclipselu
Copy link

:lgtm:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment