2014
02-12

# Shopping

Every girl likes shopping,so does dandelion.Now she finds the shop is increasing the price every day because the Spring Festival is coming .She is fond of a shop which is called "memory". Now she wants to know the rank of this shop’s price after the change of everyday.

One line contians a number n ( n<=10000),stands for the number of shops.
Then n lines ,each line contains a string (the length is short than 31 and only contains lowercase letters and capital letters.)stands for the name of the shop.
Then a line contians a number m (1<=m<=50),stands for the days .
Then m parts , every parts contians n lines , each line contians a number s and a string p ,stands for this day ,the shop p ‘s price has increased s.

One line contians a number n ( n<=10000),stands for the number of shops.
Then n lines ,each line contains a string (the length is short than 31 and only contains lowercase letters and capital letters.)stands for the name of the shop.
Then a line contians a number m (1<=m<=50),stands for the days .
Then m parts , every parts contians n lines , each line contians a number s and a string p ,stands for this day ,the shop p ‘s price has increased s.

3
memory
kfc
wind
2
49 memory
49 kfc
48 wind
80 kfc
85 wind
83 memory

1
2

#include <iostream>
#include <map>
#include <string>
using namespace std;
#define N 10005

map<string,int> elem;
int node[N];

int main()
{
int n,m,i,val,j,rank;
string str;
while(cin>>n)
{
int n1=n;
for(i=1;i<=n1;i++)
{
cin>>str;
if(str=="memory")
{
str[0]='0';
elem[str]=0;
i--;
n1--;
}
else
elem[str]=i;
}
memset(node,0,sizeof(node));
scanf("%d",&m);
while(m--)
{
for(i=1;i<=n;i++)
{
cin>>val>>str;
if(str=="memory")
str[0]='0';
node[elem[str]]+=val;
}
int cnt=0;
for(i=1;i<n;i++)
{
if(node[i]>node[0])
cnt++;
}
printf("%d/n",cnt+1);
}
}
return 0;
}

1. 一开始就规定不相邻节点颜色相同，可能得不到最优解。我想个类似的算法，也不确定是否总能得到最优解：先着一个点，随机挑一个相邻点，着第二色，继续随机选一个点，但必须至少有一个边和已着点相邻，着上不同色，当然尽量不增加新色，直到完成。我还找不到反例验证他的错误。。希望LZ也帮想想, 有想法欢迎来邮件。谢谢

2. 漂亮。佩服。
P.S. unsigned 应该去掉。换行符是n 不是/n
还可以稍微优化一下，
int main() {
int m,n,ai,aj,bi,bj,ak,bk;
while (scanf("%d%d",&m,&n)!=EOF) {
ai = sqrt(m-1);
bi = sqrt(n-1);
aj = (m-ai*ai-1)>>1;
bj = (n-bi*bi-1)>>1;
ak = ((ai+1)*(ai+1)-m)>>1;
bk = ((bi+1)*(bi+1)-n)>>1;
printf("%dn",abs(ai-bi)+abs(aj-bj)+abs(ak-bk));
}
}