题解:水题, 按照题目所说模拟即可 a[1]和a[2]尽量大 后面尽量小
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = 1e2 + 10;
int vis[maxn];
int ans[maxn];
int a[maxn], b[maxn];
int gcd(int a, int b)
{
if(b == 0) return a;
else
return gcd(b, a % b);
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n, m;
scanf("%d%d", &n, &m);
for(int i = 0; i < m; i++){
scanf("%d%d", &a[i], &b[i]);
ans[a[i]] = b[i];
}
if(m == 0){
printf("1/0\n");
continue;
}
if(m > 0)
for(int i = 1; i < a[0]; i++){
if(i == 1 || i == 2)
ans[i] = 100;
else
ans[i] = ans[a[0]];
}
for(int i = 0; i < m - 1; i++)
{
for(int j = a[i] + 1; j < a[i + 1]; j++)
{
if(j == 2)
ans[j] = ans[1];
else
ans[j] = b[i + 1];
}
}
if(m > 0){
for(int i = a[m - 1] + 1; i <= n; i++)
ans[i] = 0;
}
int ans1 = ans[1] + ans[2], ans2;
ans2 = ans1;
for(int i = 3; i <= n; i++)
ans2 += ans[i];
printf("%d/%d\n", ans1/gcd(ans1, ans2), ans2 / gcd(ans1, ans2));
} return 0;
}