标签:
Your Ride Is Here
1 /* 2 PROG:ride 3 LANG:C++ 4 */ 5 #include <iostream> 6 #include <cstdio> 7 #include <cstring> 8 #include <string> 9 #include <vector> 10 #include <algorithm> 11 #include <set> 12 #include <map> 13 #include <bitset> 14 #include <cmath> 15 #include <queue> 16 #include <stack> 17 #include<fstream> 18 using namespace std; 19 string s1,s2; 20 int main() 21 { 22 ifstream fin("ride.in"); 23 ofstream fout("ride.out"); 24 while(fin>>s1>>s2) 25 { 26 int sum1=1,sum2=1; 27 for(int i=0;i<s1.length();i++) 28 sum1=(sum1*(s1[i]-‘A‘+1))%47; 29 for(int i=0;i<s2.length();i++) 30 sum2=(sum2*(s2[i]-‘A‘+1))%47; 31 if(sum1==sum2) 32 fout<<"GO"<<endl; 33 else 34 fout<<"STAY"<<endl; 35 } 36 37 return 0; 38 }
Greedy Gift Givers
分析:模拟,开一个map维护名字和对应的收支即可,注意结束条件
1 /* 2 PROG:gift1 3 LANG:C++ 4 */ 5 #include <iostream> 6 #include <cstdio> 7 #include <cstring> 8 #include <string> 9 #include <vector> 10 #include <algorithm> 11 #include <set> 12 #include <map> 13 #include <bitset> 14 #include <cmath> 15 #include <queue> 16 #include <stack> 17 #include<fstream> 18 using namespace std; 19 const int maxn=15; 20 string x[maxn]; 21 typedef pair<int,int> p; 22 map<string,p> mp; 23 int main() 24 { 25 ifstream fin("gift1.in"); 26 ofstream fout("gift1.out"); 27 int t; 28 fin>>t; 29 for(int i=0;i<t;i++){ 30 fin>>x[i]; 31 mp[x[i]].first=0; //收入 32 mp[x[i]].second=0; //支出 33 } 34 int n=t; 35 while(n--){ 36 string name; 37 fin>>name; 38 int money,num; 39 fin>>money>>num; 40 if(num==0) continue; 41 int div=money/num; 42 int mod=money%num; 43 mp[name].second+=(money-mod); 44 for(int i=0;i<num;i++){ 45 string ch; 46 fin>>ch; 47 mp[ch].first+=div; 48 } 49 } 50 for(int i=0;i<t;i++){ 51 fout<<x[i]<<" "; 52 fout<<mp[x[i]].first-mp[x[i]].second<<endl; 53 } 54 return 0; 55 }
标签:
原文地址:http://www.cnblogs.com/wolf940509/p/5558928.html