[关闭]
@cww97 2018-03-10T04:59:28.000000Z 字数 3011 阅读 716

二、3.10 实践课

NOIP


hiho1700 相似颜色

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int INF = 0x3f3f3f3f;
  4. int getVal(char ch){
  5. if (ch >= '0' && ch <= '9') return ch - '0';
  6. return ch - 'a' + 10;
  7. }
  8. int dist(int rgb, int col){
  9. rgb = rgb * 16 + rgb;
  10. return (rgb - col) * (rgb - col);
  11. }
  12. char getChar(int val){
  13. if (val < 10) return val + '0';
  14. return val + 'a' - 10;
  15. }
  16. int main(){
  17. char ch, ch1, ch2;
  18. scanf("%c", &ch);
  19. printf("%c", ch);
  20. for (int t = 0; t < 3; t++){
  21. scanf("%c%c", &ch1, &ch2);
  22. int num = getVal(ch1) * 16 + getVal(ch2);
  23. int Min = INF, ans = -1;
  24. for (int i = 0; i < 16; i++){
  25. if (dist(i, num) < Min){
  26. Min = dist(i, num);
  27. ans = i;
  28. }
  29. }
  30. printf("%c", getChar(ans));
  31. }
  32. puts("");
  33. return 0;
  34. }

hdu6182 一道数学题

uva11462 年龄排序,注意内存

  1. #include <cstdio>
  2. #include <cstring>
  3. using namespace std;
  4. const int N = 111;
  5. int n, cnt[N];
  6. int main(){
  7. for (; scanf("%d", &n) == 1 && n;){
  8. memset(cnt, 0, sizeof cnt);
  9. for (int x;n--;){
  10. scanf("%d", &x);
  11. cnt[x]++;
  12. }
  13. bool first = true;
  14. for (int i = 1; i <= 100; i++){
  15. for (int j = 0; j < cnt[i]; j++){
  16. if (!first) printf(" ");
  17. first = false;
  18. printf("%d", i);
  19. }
  20. }
  21. puts("");
  22. }
  23. return 0;
  24. }

hdu5773 The All-purpose Zero

很巧妙的智商题。意思是数列里的 0 可以替换成任何数。做法很巧妙,如果 a1 ai 中有 z 个 0 的话,就把 ai 当作 ai − z 处理。遇到 0 不处理,最后把答案数加上总的 0 的个数即可

  1. #include<cstdio>
  2. using namespace std;
  3. const int N=1000010;
  4. int s[N],top,num;
  5. int Find(int x){
  6. int l=1,r=top;
  7. while (l<r){
  8. int mid=(l+r)>>1;
  9. if (s[mid]<=x)l=mid+1;
  10. else r=mid;
  11. }
  12. return l;
  13. }
  14. int main(){
  15. int T,n,x;
  16. scanf("%d",&T);
  17. for (int cas=1;cas<=T;cas++){
  18. scanf("%d",&n);
  19. num=0,top=0;
  20. s[0]=-100000007;
  21. for (;n--;){
  22. scanf("%d",&x);
  23. if (!x)num++;
  24. else {
  25. x-=num;
  26. if (x>s[top]) s[++top]=x;
  27. else s[Find(x)]=x;
  28. }
  29. }
  30. printf("Case #%d: %d\n",cas,top+num);
  31. }
  32. return 0;
  33. }

uva10954 优先队列

有n个数的集合S,每次可以从S中删除两个数,然后把它们的和放回集合,直到剩下一个数。每次操作的开销等于剩下的两个数之和,求解最小的总开销。

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<queue>
  4. using namespace std;
  5. int i,n,x;
  6. int main(){
  7. //freopen("fuck.in","r",stdin);
  8. for(;scanf("%d",&n)==1&&n;){
  9. priority_queue<int,vector<int>, greater<int> >q;
  10. for (int i=1;i<=n;i++){scanf("%d",&x);q.push(x);}
  11. int ans=0;
  12. for (int i=1;i<n;i++){
  13. int x=q.top();q.pop();
  14. int y=q.top();q.pop();
  15. ans+=x+y;
  16. q.push(x+y);
  17. }
  18. printf("%d\n",ans);
  19. }
  20. return 0;
  21. }

hdu5774 Where Amazing Happens

第一次看见这种题目吧

  1. #include<cstdio>
  2. #include<map>
  3. #include<string>
  4. #include<iostream>
  5. using namespace std;
  6. map<string,int>mp;
  7. int a[100];
  8. int main(){
  9. //freopen("fuck.in","r",stdin);
  10. mp["Cleveland Cavaliers"]=0; a[0]=1;
  11. mp["San Antonio Spurs"]=1; a[1]=5;
  12. mp["Miami Heat"]=2; a[2]=3;
  13. mp["Dallas Mavericks"]=3; a[3]=1;
  14. mp["L.A. Lakers"]=4; a[4]=11;
  15. mp["Boston Celtics"]=5; a[5]=17;
  16. mp["Detroit Pistons"]=7; a[7]=3;
  17. mp["Chicago Bulls"]=8; a[8]=6;
  18. mp["Houston Rockets"]=9; a[9]=2;
  19. mp["Philadelphia 76ers"]=10; a[10]=2;
  20. mp["Seattle Sonics"]=11; a[11]=1;
  21. mp["Washington Bullets"]=12; a[12]=1;
  22. mp["Portland Trail Blazers"]=13;a[13]=1;
  23. mp["Golden State Warriors"]=14;a[14]=2;
  24. mp["New York Knicks"]=15; a[15]=2;
  25. mp["Milwaukee Bucks"]=16; a[16]=1;
  26. mp["St. Louis Hawks"]=17; a[17]=1;
  27. mp["Philadelphia Warriors"]=18;a[18]=2;
  28. mp["Syracuse Nats"]=19; a[19]=1;
  29. mp["Minneapolis Lakers"]=20; a[20]=5;
  30. mp["Rochester Royals"]=21; a[21]=1;
  31. mp["Baltimore Bullets"]=22; a[22]=1;
  32. int T,ans;
  33. string st;
  34. scanf("%d\n",&T);
  35. for (int cas=1;cas<=T;cas++){
  36. getline(cin,st);
  37. if (mp.find(st)==mp.end())ans=0;
  38. else ans=a[mp[st]];
  39. printf("Case #%d: %d\n",cas,ans);
  40. }
  41. return 0;
  42. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注