【mixing milk】 /* ID: wangqia6 TASK: milk LANG: C++ */ #include <fstream> #include <cstring> using namespace std; int main() { ifstream infile; ofstream outfile; infile.open("milk.in"); outfile.open("milk.out"); long need; int sum; infile >> need >> sum; long count[1005]; memset(count,0,sizeof(count)); int money; long tot; for (int i = 0; i < sum; i++) { infile >> money >> tot; count[money] += tot; } long ans = 0; for (int i = 0; i<= 1005; i++) if (count[i] >= need) { ans += i * need; break; } else { ans += i * count[i]; need -= count[i]; } outfile << ans << endl; infile.close(); outfile.close(); return 0; } 【barn repair】 /* ID: wangqia6 TASK: barn1 LANG: C++ */ #include <fstream> using namespace std; void swapq(int &a,int &b) { int t = a; a = b; b = t; } int main() { ifstream infile; ofstream outfile; infile.open("barn1.in"); outfile.open("barn1.out"); bool vis[205]={0}; int i,j,tmp,sell_sum,stall_sum,cow_sum,head = 205,tail = -1; infile >> sell_sum >> stall_sum >> cow_sum; for (i = 0; i < cow_sum; i++) { infile >> tmp; vis[tmp] = true; if (tmp < head) head = tmp; if (tmp > tail) tail = tmp; } int p = head,q,ans = 0,untot = 0,istot = 0,len[205]; while (p <= tail) { q = p; while ((q <= tail) && (vis[q])) q++; istot++; ans += q - p; if (q > tail) break; p = q; while ((q <= tail) && (!vis[q])) q++; untot++; len[untot] = q - p; p = q; } if (istot > sell_sum) { for (i = 1; i < untot; i++) for (j = i + 1; j<= untot; j++) if (len[i] > len[j]) swapq(len[i],len[j]); for (i = 1; i <= istot - sell_sum; i++) ans += len[i]; } outfile << ans << endl; infile.close(); outfile.close(); return 0; } 【calf flac】 /* ID: wangqia6 TASK: calfflac LANG: C++ */ #include <fstream> #include <cctype> using namespace std; ifstream infile; ofstream outfile; char list[20005],comp[20005]; int seat[20005],tot_sum = 0,tot_alpha = 0,ans = 0,leftp,rightq; void initdata() { char ch; infile.open("calfflac.in"); outfile.open("calfflac.out"); while (infile.get(ch)) { tot_sum++; list[tot_sum] = ch; if (isalpha(ch)) { tot_alpha++; comp[tot_alpha] = tolower(ch); seat[tot_alpha] = tot_sum; } } return; } void solve() { int p,q; for (int i = 1; i <= tot_alpha; i++) { p = i; q = i; while ((p > 1) && (q < tot_alpha) && (comp[p - 1] == comp[q + 1])) { p--; q++; } if (q - p + 1 > ans) { leftp = seat[p]; rightq = seat[q]; ans = q - p + 1; } p = i + 1; q = i; while ((p > 1) && (q < tot_alpha) && (comp[p - 1] == comp[q + 1])) { p--; q++; } if (q - p + 1 > ans) { leftp = seat[p]; rightq = seat[q]; ans = q - p + 1; } } return; } void outitdata() { outfile << ans << endl; for (int i = leftp; i <= rightq; i++) outfile << list[i]; outfile << endl; infile.close(); outfile.close(); return; } int main() { initdata(); solve(); outitdata(); return 0; }