全部评论
推了半个小时杨辉三角,过了0.4,发现和暴力的复杂度一样,心态炸了
第二题我的思路是,计算每个节点到最终节点N的最短距离。用Floyd。然后统计节点距离大于等于2的节点数,如果节点数是奇数,则先手必赢,如果节点数是偶数,则先手必输。动手模拟下,因为大家都不想去下距离为1的节点数,因为谁下谁输(下一步就是最后的N节点,对手一定会赢),然后都去下距离大于2的节点,然后看节点数是奇数还是偶数来判断谁输。
借楼涨粉,第一题暴力,第二题拓扑博弈,https://nuoyanli.blog.csdn.net/article/details/120037476
第二题 我是反向建图然后跑拓扑做dp bool ans[maxn]; vector<int> G[maxn]; int du[maxn]; void solve() { int n, m; cin >> n >> m; string s; for(int i = 1; i <= n; ++i) { ans[i] = true; G[i].clear(); du[i] = 0; } for(int i = 0; i < m; ++i) { int u, v; cin >> u >> v; if(u == n) continue; G[v].push_back(u); ++du[u]; } cin >> s; queue<int> que; que.push(n); while(!que.empty()) { int v = que.front(); que.pop(); bool now = !ans[v]; for(int u : G[v]) { ans[u] = min(ans[u], now); --du[u]; if(du[u] == 0) que.push(u); } } if(s == "Alice") { if(ans[1]) cout << "Alice" << endl; else cout << "Bob" << endl; }else { if(!ans[1]) cout << "Alice" << endl; else cout << "Bob" << endl; } }
第一题 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = Integer.parseInt(scanner.nextLine()); BigInteger bigInteger1 = new BigInteger("1000000007"); BigInteger[] nums = new BigInteger[N]; String next = scanner.nextLine(); String[] s = next.split(" "); for(int i = 0 ; i < N ; i++){ BigInteger bigInteger = new BigInteger(s[i]); nums[i] = bigInteger; } for(int j = nums.length - 1; j > 0 ; j--){ for(int k = 0 ; k < j ; k++){ nums[k] = (nums[k + 1].subtract(nums[k])).mod(bigInteger1); } } System.out.println(nums[0]); } }
麻中麻,第一题用例和自己模拟的都对,提交0分,以为是溢出,换long一样0
第一题明明这么简单,怎么做都是0,心态崩了😥
第一题超时,运气好能跑到90%,运气差65%
def judge(nums):
n=len(nums)
for i in range(n-1,0,-1):
nums=[nums[j+1]-nums[j] for j in range(i)]
print(int(nums[0]%(10**9+7)))
def main():
raw_input()
group=raw_input().strip()
nums=group.split(" ")
nums=[int(num) for num in nums]
judge(nums)
if __name__ == '__main__':
main()
第二题有解题思路吗?⚽️⚽️
第一题只过了40。不清楚问题在哪,有老哥帮忙看看吗?代码没保存,凭记忆复现的。
有大佬分享第二题的解题思路吗
第一题有老哥贴代码吗,怎么调都是0
相关推荐
点赞 评论 收藏
分享

点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 评论 收藏
分享